268 Commits

Author SHA1 Message Date
Matthew Brush
4efcbab332 Include what you use
This is a mega-commit - because most of it had to be done in one go
otherwise some commits would fail to compile - that attempts to fix a
few problems with Geany's includes as well as various other related
cleanups. After this change it's easier to use includes and there's
little worry about which order things are included in or who includes
what.

Overview of changes:

* Include config.h at the start of each source file if HAVE_CONFIG_H
  is defined (and never in headers).
* Go through each source file and make the includes section generally
  like this:
  - Always config.h first as above
  - Then if the file has a header with the same name, include that
  - Then include in alphabetical order each other internal/geany header.
  - Then include standard headers
  - Then include non-standard system headers
  - Then include GLib/GTK+ related stuff
* Doing as above makes it easier to find implicit header include
  dependencies and it exposed quite a few weird problems with includes
  or forward declarations, fix those.
* Make geany.h contain not much besides some defines.
  - Add a little header file "app.h" for GeanyApp and move it there
  - Move "app" global to new "app.h" file
  - Move "ignore_callback" global to "callbacks.h"
  - Move "geany_object" global to "geanyobject.h"
* Add an include in "geany.h" for "app.h" since GeanyApp used to be
  defined there and some plugins included this header to access
  GeanyApp.
* Include "gtkcompat.h" everywhere instead of gtk/gtk.h so that
  everywhere sees the same definitions (not a problem in practice AFAIK
  so this could be changed back if better that way.
* Remove forward declarations from previous commits as some people
  apparently consider this bad style, despite that it reduces inter-
  header dependencies.

TODO:
* As always, to test on win32
* As always, to test with not Autotools
* Test plugins better, both builtin and geany-plugins, likely API/ABI bump
* Test with various defines/flags that may change what is included
* win32.[ch] not really touched since I couldn't test
2014-05-21 15:37:19 -07:00
Colomban Wendling
aeab183ef2 Merge branch 'unified-encoding-combo-boxes' 2014-04-15 15:57:13 +02:00
Colomban Wendling
8c5e198cf1 Unify encoding combo boxes
Make all encoding combo box display a list with encodings grouped by
categories into sub-menus, making it easier to find the appropriate
encoding than in a big single-level list.

This is what was used in the Open dialog, but not in the Preferences
dialog or the Find in Files dialog.  This also makes the encoding
combo boxes behave more like the encoding menus.
2014-04-15 15:51:49 +02:00
Colomban Wendling
7473e4b1d9 Add defensive checks for function receiving a GeanyDocument argument
Always check the passed-in GeanyDocument argument is a valid one, not
to possibly work on an invalid document.
2014-01-22 17:38:29 +01:00
Colomban Wendling
17a7469b68 Avoid a few unnecessary widget lookups 2014-01-09 17:50:30 +01:00
Colomban Wendling
680a556fff Find when activating the find entry in the replace dialog 2014-01-09 17:34:50 +01:00
Nick Treleaven
0998f1c19c Make code more readable by renaming poorly named macros NZV and NVL
Closes #159
2013-08-14 21:54:20 -07:00
Matthew Brush
79db59d019 Add API docs for search_show_find_in_files_dialog()
This function is used in File Browser plugin and in Tree Browser,
GProject, and GeanyPrj plugins from Geany-Plugins.
2013-06-15 12:45:45 -07:00
Colomban Wendling
5412a244ba Fix crash with bulk pattern replacements (introduced with c83a93e)
"regex_match_text" and "regex_matches" being globals, performing
several searches and then the replacements separately lead to them
having unexpected values, resulting in incorrect behavior and crash.

Fix this by removing the globals and instead make the search functions
return match details.  Not only this fixes the issue, but also make the
code a lot more maintainable by not having globals introducing side
effects (proof of them being an issue is that c83a93e inadvertently
broke things bad).
2013-04-13 17:06:47 +02:00
Nick Treleaven
4fcce9cc00 Add symbol list Find in Files popup menu item 2013-03-25 15:57:56 +00:00
Colomban Wendling
235b8613fb Use GSlice to allocate find_range() elements 2013-03-24 18:47:55 +01:00
Colomban Wendling
4f78efc9f1 Unify algorithm for searching all matches inside a range
Instead of re-implementing the search-all algorithm everywhere it is
needed, move it to a re-usable function.  This is useful because some
care is required to avoid improper rematches and endless loop, so
avoiding duplication is important (especially if something has to be
fixed someday).
2013-03-24 15:53:39 +01:00
Colomban Wendling
c83a93eb65 Fix search/replace for the replacement not to change search results
Fix the search & replace algorithm to make sure a replacement won't
possibly affect the next one (e.g. in case of lookahead and lookbehind
regular expressions).

To do so, first find all occurrences and only then perform replacements,
instead of doing both together.

This fixes searching/replacing of any pattern that may be affected by
its replacement (e.g. patterns that look for something not a character
in the match range), including:

 * Start/end of line:
   Before this change, searching with regular expression "^A" and
   replacing with an empty string on the input "AA" would have resulted
   in an empty output ("^A" matching again after removing the first
   one).  Now it properly only removes the leading "A".
 * Lookahead/lookbehind:
   Pattern "(?<=a)b" with empty replacement and input "abb" would have
   resulted in the output "a" instead of "ab".
 * And more generally, many patterns matching non-characters like
   positions or out-of-match characters.
2013-03-24 15:50:22 +01:00
Nick Treleaven
fd8ba60b4a Disable start of word checkbox when whole word checkbox is enabled 2013-03-16 13:47:28 +00:00
Nick Treleaven
14878850cd Don't find start of word when whole word matching should prevent it 2013-03-16 13:26:52 +00:00
Colomban Wendling
8ece89096d Merge branch 'master' into gtk3-support 2013-01-29 15:29:10 +01:00
Colomban Wendling
83e7afc199 Fix return value of search_find_text() when the match is out of bounds
When performing a regular expression search on a range, and there is a
match past the end of the range, search_find_text() used to improperly
return the position of the match, but without filling the
Sci_TextToFind structure.  This lead to the calling code assume there
was a match, and maybe read the uninitialized fields in the
Sci_TextToFind structure, thus leading to undefined behavior.

So, fix search_find_text() so it properly returns -1 when there is a
match but it is outside the bounds.
2012-12-10 22:45:34 +01:00
Nick Treleaven
a1022060d2 Show Find in Files status summary on Windows 2012-11-27 14:16:30 +00:00
Colomban Wendling
6409840d4a Get rid of GtkComboBoxEntry API and use GtkComboBoxText API
Use the GtkComboBoxText API and the GtkComboBoxEntry replacement API
and map those to the old equivalents if not available.

This changes the type exposed by ui_combo_box_add_to_history() from
GtkComboBoxEntry to either GtkComboBox (under GTK2) or GtkComboBoxText
(under GTK3).  This should not be too much of an issue since
GtkComboBoxEntry and GtkComboBoxtext are subclasses of GtkComboBox,
but this will still emit warnings when when the calling code passes
a GtkComboBoxEntry pointer to ui_combo_box_add_to_history().

However, this requires the calling code to use the same mapping as we
do (GtkComboBoxText = GtkComboBox on GTK2, even on 2.24), or things
will blow and it'll be hard to understand why.  This wouldn't be an
issue if the calling code includes our gtkcompat.h header everywhere
it deals with combo boxes, which will be the case if it includes the
Geany headers everywhere but probably won't otherwise.  Oh dear.

A possible kind of workaround may be for ui_combo_box_add_to_history()
to do type-checking on its argument and use the actually correct API
for that type.
2012-10-08 20:08:06 +02:00
Colomban Wendling
a763e307f7 Don't access GtkWidget fields directly
Since many accessor are new in GTK versions we don't depend on, add
a header that defines them to the direct access if they aren't
available.
2012-10-08 20:08:06 +02:00
Colomban Wendling
eeddd6f720 Move custom styles to a resource file 2012-10-08 17:51:19 +02:00
Colomban Wendling
4d16735380 Don't access GtkDialog fields directly 2012-09-13 16:34:18 +02:00
Colomban Wendling
66b93d2d8d Fix "mark all" search feature when using regular expressions
Use the proper, full-featured, regular expression engine we use
everywhere else rather than Scintilla's stripped-down one.

Closes #3564132.
2012-09-02 14:47:07 +02:00
Colomban Wendling
69d8295c5e Don't try to unref NULL regex 2012-09-02 14:17:34 +02:00
Colomban Wendling
d80bc7ce56 Update FSF address
Closes #3557875.
2012-08-24 19:25:57 +02:00
Colomban Wendling
5110fab0e1 Fix search and replacement of empty matches (again)
f4eb89cd7d79738a9c6c45e29abdd9d15d22e4fd was partially wrong and
removed legitimate re-matches when two different matches ends at the
same position.  Particularly, the replacement changes are reverted.

Interestingly, Perl and Python does not agree on how to do such
replacements.  Python does what I did in the above-cited commit, e.g.
doesn't replace twice if the match end overlaps, but Perl does.
Perl looks more legitimate here since both Python and Perl does find
the overlapping matches when performing a search, so Python is the odd
guy here doing it differently on replace than it does upon search.

For example, replacing using the pattern "a?(?=b)" and the replacement
string "_":

	Python: ababcdb -> _b_bcd_b
	Perl:   ababcdb -> __b__bcd_b

But finding using the same pattern on the same input gives the same
results on both:

	Python: ababcdb -> ['a', '', 'a', '', '']
	Perl:   ababcdb -> ['a', '', 'a', '', '']

Anyway, GLib and us claim to support "Perl-compatible regular
expressions", so we gotta follow Perl, especially in such doubtful
situations.
2012-07-28 19:23:37 +02:00
Colomban Wendling
f4eb89cd7d Fix search and replacement of empty matches
Regular expressions might match empty ranges, which weren't handled
properly, but generally simply omitted.

For example, the regular expression "^$" (empty line) never matched
because we assumed empty results were not interesting, and actually
needed more care in the code.  Alike, an expression matching only on
its lookahead part, like "a?(?=b)" against "b", would stop further
search, although it could even match a non-empty range if "ab" is
present later in the input.  This last kind of expressions also lead
to double-replacement because they first matched "ab" and then "b"
alone when re-matching after the "a" replacement.

This commit fixes:
 * searching when the matched range is empty;
 * step-by-step search when matching an empty range;
 * double replacement when the pattern re-matches an empty range
   straight after a replacement;
 * replacement to and empty string when the matching an empty range.

A know issue though is the step-by-step replacement that won't replace
an empty match but rather find the next match.
2012-07-28 00:32:26 +02:00
Colomban Wendling
a091238617 Fix searching out of document range
If a search matched the very last character of the document, next
search attempt started out of the document bounds.  This even lead
to an infinite loop due to an improper sanity check.

By the way, this fixes matching of contiguous results, as the next
search used to improperly skip one character after the result.
Although this looks like a huge issue, it was actually visible almost
only on the match count since the whole matching line was printed.
2012-07-28 00:32:26 +02:00
Nick Treleaven
f90bdc5957 Only set Find in Files directory once per-document
Use the current document's directory unless the directory field has
already been edited and the current document has not changed.
Otherwise, prepend the current document's directory to the drop-down
history in case it is wanted.

This is useful to avoid losing the edited directory when it is less
likely the user wants to use the current document's directory.
2012-07-26 16:13:34 +01:00
Colomban Wendling
1c2c455b1d Update copyright information 2012-06-18 01:15:04 +02:00
Colomban Wendling
78432b5806 Find in files: split extra options like a shell would do
Don't simply split the the extra options string on spaces to build the
grep argument list but rather split it in a shell-style fashion.

This is probably more intuitive for most users, is more consistent with
e.g. custom commands, and allows for spaces in an option or its
argument.

Closes #3516263.
2012-04-10 04:21:59 +02:00
Nick Treleaven
b287553e4a Use 'SETPTR' instead of 'setptr'
This makes it clearer we're using a macro.
2012-01-25 16:26:16 +00:00
Jiří Techet
d4b2b89d00 Maybe != may be 2012-01-11 22:57:31 +01:00
Nick Treleaven
f0ca50cf20 Fix showing Find/Replace regex errors on status bar 2012-01-03 16:21:12 +00:00
Nick Treleaven
387d071b60 Fix escaping replacement text for regex matching (oops) 2011-12-26 13:01:54 +00:00
Matthew Brush
fb8e061242 Prevent warning about comparing signed and unsigned values
The g_match_info_fetch_pos() function uses a signed value for the match_num
parameter, even though values less than 0 are not valid, so a cast is used.
2011-12-25 14:44:32 -08:00
Nick Treleaven
773d7e42d2 Let GRegex handle escape sequences itself 2011-12-25 17:22:06 +00:00
Nick Treleaven
21f0715381 Fix \b regex word boundary always matching at start of search 2011-12-25 13:42:19 +00:00
Nick Treleaven
c2481ccb95 Use GRegex matching for Find & Replace commands 2011-12-25 13:23:06 +00:00
Dimitar Zhekov
4ffbd8f9ad split "always wrap search and hide find dialog" pref into "always wrap search" and "hide find dialog" 2011-12-05 21:54:38 +01:00
Colomban Wendling
36ebb1f2b7 Use canonical macros for stock items rather than plain strings
This makes the code more readable, potentially more future-proof (if
the actual string changes) and better style (catches possible typos at
build-time).
2011-10-30 22:01:49 +01:00
Matthew Brush
82146e953f Remove max length limit of 248 characters on search dialogs 2011-10-23 00:41:50 -07:00
Matthew Brush
182bdc3b17 Replace GTK_BIN(...)->child with gtk_bin_get_child(...) 2011-10-11 21:30:28 -07:00
Colomban Wendling
d06e9f4575 Remove $Id$ and $Date$ SVN keywords 2011-10-09 22:57:35 +02:00
Colomban Wendling
5d606ce351 Deprecate ui_widget_set_tooltip_text() in favor of gtk_widget_set_tooltip_text()
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5840 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-06-13 18:41:50 +00:00
Colomban Wendling
d455e83d6e Also use the actual user search in the combo box history
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5833 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-06-03 13:41:00 +00:00
Colomban Wendling
6f9d845181 In messages show the actual text user entered in Find and Replace dialogs
Previously we could put into a message a string where escape sequences
were already translated.

In the code, now we pass the original text together with the one
that is actually searched for.  New `original_text' field was added to
GeanySearchData.  A bug was fixed in document.c:show_replace_summary(): it
did not escape the "No matches found for ..." string.

Patch by Eugene Arshinov, thanks.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5832 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-06-03 13:40:42 +00:00
Colomban Wendling
6e6b4a61fc Make search.c:on_replace_dialog_response() a little more readable
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5797 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-05-17 13:47:36 +00:00
Colomban Wendling
a0d6a1f618 Fix pattern filtering when not searching in subdirectories
grep's --include option doesn't filter files passed explicitly to grep,
so when we build the file list to search in, take the filters into
account.
Also drop the --include options in this case since they aren't useful.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5755 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-05-01 14:38:57 +00:00
Colomban Wendling
e48def3c68 Use project patterns in the FIF dialog
User can now select what kind of file patterns should be used:
 * all: all files are searched
 * project: project patterns are used (only if a project is open)
 * custom: manually entered custom patterns are used

Based on a patch by Jiří Techet, thanks.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5753 ea778897-0a13-0410-b9d1-a72fbfd435f5
2011-04-30 21:50:37 +00:00