GPS provides extensive search capabilities among its different
elements. For instance, it is possible to search in the currently
edited source file, or in all the source files belonging to the
project, even those that are not currently open. It is also possible
to search in the project view (on the left side of the main GPS
window), ...
All these search contexts are grouped into a single graphical window,
that you can open either through the menu Navigate->Find/Replace...
, or
the shortcut <Ctrl-F>.
By default, the search window is floating, ie appears as a dialog on top of
GPS. You can choose to put it inside the multiple document interface
permanently for easier access. This can be done by selecting the menu
Window->Floating
, and then drag-and-dropping the search window in a
new location if you wish (for instance above the Project View).
Selecting either of these two options will pop up a dialog on the screen, similar to the following:
On this screen shot, you can see three entry fields:
Options
button and selecting the
appropriate check box, or by opening the combo box (click on the arrow
on the right of the entry field).
In this combo box, a number of predefined patterns are provided. The
top two ones are empty patterns, that automatically set up the
appropriate fixed strings/regular expression mode. The other regular
expressions are language-specific, and will match patterns like Ada
type definition, C++ method declaration, ...
Clicking on the arrow on the right will display the list of all possible contexts. This list includes:
Project View
Projects, Directories, Files, Entities
. The search in entities
may take a long time, search each file is parsed during the search.
Open Files
Files...
section below.
Files...
*.ad?
for all files ending with .ad and any
trailing character. The directory specified where the search starts, and
the Recursive search button whether sub directories will be searched
as well.
The Scope entry is used to restrict the search to a set of language
constructs, e.g. to avoid matching on comments when you
are only interested in actual code, or to only search strings and
comments, and ignore the code.
Files From Project
Files...
section above.
Current File
Files...
section above.
Project Browser
The default value for Look In
is set through various means: by
default, GPS will select a context that matches the currently selected
window. For instance, if you are in an editor and open the search dialog,
the context will be set to Current File
. But if the project view is
the active window, the context will be set to Project View
.
Optionally, GPS can remember the last context that was set (see the preference
Search/Preserve Search Context
. If this is set, and an editor is
selected, GPS will remember whether the last time you started a search from
an editor you decided to search in Current File
or Files From
Project
for instance.
Finally, you can create key shortcuts (through the /Edit/Key Shortcuts
menu, in the Search
category) to open the search dialog and set the
context to a specific value.
The second part of the window is a row of buttons, to start the search (or continue to the next occurrence), and to display the options.
There are five check boxes in this options box.
"Regexp"
Search for:
field.
The grammar followed by the regular expressions is similar to the Perl and
Python regular expressions grammar, and is documented in the GNAT run time file
g-regpat.ads. To open it from GPS, you can use the open from project
dialog (File->Open From Project...
) and type g-regpat.ads. See
Open From Project for more information on this dialog.
"Whole Word"
Select on Match
Close on Match
"Case Sensitive Search"
"Case Preserving Replace"
Pressing the Find
/ Previous
buttons performs an interactive
search.
It stops as soon as one occurrence of the pattern is found.
search. Once a first occurrence has been found, the Find
button is
renamed to Next
.
You then have to press the Next
button (or the equivalent shortcut
<Ctrl-N>) to go to the next occurrence.
If you use the Find all
button, the search widget will start
searching for all occurrences right away, and put the results in a new
window called Locations
, See The Locations View.
The Replace
and Replace & Find
buttons are grayed out as long as
no occurence of the pattern is found. In order to enable them, you have to
start a search, e.g. by pressing the Find
button. Pressing Replace
will replace the current occurence (and therefore the two buttons will be
grayed out), and Replace & Find
will replace the occurence and then
jump to the next one, if any. If you don't want to replace the current
occurence, you can jump directly to the next one by pressing Next
.
The Repl all
button will replace all the occurences found. By default,
a popup is displayed and ask for confirmation. It's possible to disable this
popup by either checking the box "Do not ask this question again", or by going
in the Search pannel of the preferences pages, and unchecking "Confirmation for
'Replace all'". The confirmation popup can be reenabled through this checkbox.
As most GPS components, the search window is under control of the multiple document interface, and can thus be integrated into the main GPS window instead of being an external window.
To force this behavior, open the menu Window
, select
Search
in the list at the bottom of the menu, and then select
either Floating
or Docked
.
If you save the desktop (File->Save More->Desktop
, GPS will
automatically reopen the search dialog in its new place when it is
started next time.