Search and replace
One of the main usages for TrapEd is its context-sensitiv search and
replace facility. Depending on the selected item in the explorer-tree
(project, template, file or record) you get the corresponding
Search/replace-dialog with pressing Ctrl+F or the Search all -dialog
with Ctrl+L.
The following image shows the dialog when a project is marked. If you
have marked a template (on the left explorer-tree-side) only the
search-attributes of templates are shown.
You will only see those attributes that you have configured, see
Menu>Options (Attributes)
Search/replace-dialog

Search/replace-dialog
In the Search/replace-dialog you can select which attributes you
want to search. All attributes for the special item (template, file or
record) are listed. In case of a project everything below this project
is searched, so you can choose from all the different item-types
(project, template, file or record) and the specific attributes.
To deselect an attribute simply click on it while pressing the
Ctrl (or Strg)-Button.
Assume you want to search all the templates for the keyword INCLUDE
below the root-project. You mark the highest/root-project in the
explorer-tree, open the Search/replace-dialog and enter INCLUDE as a
search-term and mark the attribute body from the template-attributes,
than click Search next. The first found word INCLUDE in a template
will be highlighted (you may directly overwrite the word if you wish,
or you may enter a replace-term and than click Replace).
The following actions are possible inside the Search/replace-dialog:
| Regexp: | Should be checked if you want to search for a regular expression (see below) |
| Ignore case: | Should be checked if upper- or lower-case doesn't matter |
| Search next: | Search for the next occurrence of the given search-term |
| Skip: | Skip this template/record/file/project and go on with the search for the given search-term in the next item |
| Replace: | With a previous search, replace the found "search-term" with the given replace-term |
| Replace & Search: | Like replace but immediately search for the next occurrence of search-term |
| Replace all: | Replace all occurrences of search-term with the replace-term without asking |
The search is initialized when the Search/replace-dialog pops
up. If you are modifying the search-term and/or the replace-term or
changing the values of the checkboxes for Regexp or
Ignore case the search won't start at the beginning but
instead will simply go on.
To start again from the beginning, click Cancel (or
Esc) mark the item from which you want to start the
search in the left explorer-pane and open the Search/replace (or
"Search all")-dialog again.
Depending on the size of the project and the number of
templates/records/files below opening the dialog may take a while.
Attention: if you're doing replacements the affected template, file, ... is
immediately and automatically saved (and there is only one step of
undo in this case). This is called the auto-save feature of TrapEd.
"Search all"-dialog
You also may want to search all occurrences of the term
INCLUDE (or search for all occurrences of
jsp:useBean, as shown in image {{#imgresult "Search all"-result-dialog]] search). Open the
Search-all-dialog, which looks similar to the
Search/replace-dialog. After entering your search-term and pressing button
Search all a new dialog is opened with the results of
your search.

"Search all"-result-dialog
As you can see in the above result-dialog, we have searched for "jsp:useBean". Each match is displayed even if there are more matches inside one template.
You can get a resultlist which only shows one hit per template by marking the checkbox Show one hit per template, project, file or record. In this case only the last match will be listed in column Matches with 'jsp:useBean'.
The result-dialog only shows the columns you wish. As you can see in the
above image you can mark the columns (by opening the context-menu of
the title-row (right-mouse-click) and marking the visible
columns). Clicking on a column-title (with the right-mouse-button will
sort this column.
The following columns are available:
- Type - Project, Template, Record or File (displaying this column only makes sense if you have searched in attributes belonging to different types).
- ID - the Vignette-ID of the template, project, ... (e.g.
/ci/1121)
- Name - the name of the template, project, ...
- Project - the project in which the template, ... was found
- Attribute - the attribute you searched for. In the image above we searched for occurrences of
jsp:useBean in the template-body. (displaying this column only makes sense, if you have search in multiple attributes).
- Matches - the matching string (in this case from the
body-attribute). You can specify the length of the matching string which is displayed in the Option-dialog.
Clicking on a match will open the corresponding template (in the background) and
mark the match in the right-pane of TrapEd.
You can also mark more matches (with pressing the usual Ctrl/Strg-key
or the Shift-key while clicking on the rows; with Ctrl-a
you can mark all rows (see Shortcuts)).
If I'm developing Vignette-projects, I usually have a lot of
test-templates which are useless after a while, so I rename them to
previous-name_not_used. Now I can search for all
templates with _not_used in their name, mark all hits in
the "Search all"-result-dialog and then press Delete selected (which deletes all selected/marked items from the
attr-file.
For documenting purposes you can copy the marked items to the clipboard (as usually
pressing Ctrl-c).
E.g. my projectmanager wants to have a list of all templates which
are cached.
I search for all occurrences of y for the
template-attribute cache. In the "Search
all"-result-dialog I hide all columns (except ID and
Name), mark everything, copy to clipboard paste it into
an email (Ctrl-a, Ctrl-c, Ctrl-v) and as always my
projectmanager is astonished how fast I retrieved this list ;-)
This would be the resulting list for the jspsamles:
ID Name
/ci/3a jsp_cms_util
/ci/3f jsp_needsLogin_inc
/ci/50 jsp_cds_DBSearchResultBean
/ci/52 jsp_cds_check_user_cookie_inc
/ci/53 jsp_cds_save_user_cookie
/ci/55 jsp_cds_faq_build_table
/ci/56 jsp_cds_db_show_record
/ci/63 HelloTclCached
/ci/64 HelloJspCached
Regular expressions
To get all out of the search-facility you may want to use regular
expressions. For a quick intro here is a small summary of some regular
expression-features (for a complete reference you may want to have a
look at the tcl-pages for regexp
and re_syntax).
The following characters have a special multiplying meaning:
* | a sequence of 0 or more matches of the previous character |
+ | a sequence of 1 or more matches of the previous character |
? | a sequence of 0 or 1 matches of the the previous character |
{m} | a sequence of exactly m matches of the previous character |
{m,} | a sequence of m or more matches of the previous character |
{m,n} | a sequence of m through n (inclusive) matches of the previous character; m may not exceed n |
If you append a ? to the above characters you get the
non-greedy quantifiers, which match the same possibilities, but prefer
the smallest match rather than the largest match.
Suppose you have:
"<td>Hello</td><td>World</td>"
Search for "<td>.*</td>" would match the entire
term, but searching for: "<td>.*?</td>" would
only match "<td>Hello</td>" .
The following characters are used for matching:
. | (this is the dot) matches any single character |
[a-z] | a bracket expression. It matches any single character from the list. If the list begins with ^, it matches any single character not from the rest of the list (e.g. [^a-zA-Z] matches anything which is not a letter) |
(re) | for grouping, you can reference anything in such a group in the replace term with the number of the group with \n (starting with 1) |
^ | matches at the beginning of a line (be careful, that in a large textbox, e.g. for the body or path-attribute, ^ refers to the beginning of the whole text) |
$ | matches at the end of a line (see remark for ^; in the body or path-attribute $ refers to the end of the whole text) |
You can also use the following shortcuts for some character-classes:
\d | Any digit, that is [0-9]. Use \D for everything which is not(!) a digit |
\w | Any alphanumeric character and the underscore, that is [a-zA-Z0-9_]. Analogue \W matches any non-alphanumeric character. |
\s | whitespace characters, that is [\t\n ]. \S matches anything that's not a whitespace. |
Some examples
1. Renaming project/templatenames
You have named all your templates (according to your
programming-guidelines) like this: x_name (with
x being a digit). Now you realize that you need
one more subproject (and you already have 10 subprojects), you give it
the number 10 (let's say 10_example). Now
this subproject will be sorted between 0_something and
1_anything in Vignette's annoying Project Manager
(because of the literal sorting).
To avoid this, you want to rename everything with
x_name to 0x_name (so that you have
two digits at the beginning of the name.
You simply enter:
^([0-9]_.+)$ (or ^(\d_.+)$)
as a search-term and:
0\1
as the replace term, mark Regexp and search over the
attribute Name of Projects and
Templates (if you already have references to
library-templates in the template-code you may also mark the
body-attribute to do the substitutions there as well, but
be careful this may replace more than you wish, so take a careful
look!)
The search-term matches everything which begins with a digit followed
by an underscore and then any character (but at least one (+)).
In the replace term you prefix everything with your 0 afterwards you
append the first matched group \1 (which is everything in () in
the search-term, that is the whole name). This replaces
e.g. 1_Lib with 01_Lib (remember to click on
the regexp-checkbox to enable regular-expressions).
2. Replacing references in templates
To replace references in the template-body, e.g. INCLUDE LIBNAME 1_Lib_Image or SOURCE 1_Lib_Image, you can
test the following search and replace term:
search:
INCLUDE LIBNAME (\d_.+?\W)
and replace with
INCLUDE LIBNAME 0\1
(the same goes with SOURCE).
Match INCLUDE LIBNAME and then one digit (\d)
an underscore and at least one character (non-greedy: .+?) until a
character appears which is not an alphanumeric or underscore character
(\W).
You have to be sure that you don't use any whitespace in your template
names (like "1 Lig Image"), because whitespaces will stop
the matching templatename!
3. Search all submitted GIF-images
You want to have a list of all images that were submitted to
Vignette. Open the "Search all"-dialog. Simply search for (don't
forget to check the regexp-checkbox!):
.*?\.(gif|GIF) (Match everything up to .gif or .GIF.)
Mark the attribute Name for file-attributes and click
on Search all.
4. Replace <Tabs> with spaces
Often Tabs are displayed with a different number of spaces (e.g. in
TrapEd tabs are assumed to be 8 characters wide). If you want to
have a unique code layout you may replace all tabs with e.g 4
spaces. But you cannot enter the tab as a search-term (because tab
moves the focus to the next text-element). So simply insert:
\t
as a search-term and the according number of spaces as replace-term
and check Regexp.
Then select body of the template-attributes and click
on Replace all.
5. Search for all templates that have no path (or an empty body)
Open "Search all"-dialog
Search for:
^$
and mark Regexp and the attribute Paths (or body) in templates.
6. Change the NameOfTable (or PrimaryKeyName) of all Records in a specific project
Mark the specific project in the tree and open the Search/replace-dialog search for the old tablename or primary-key-name, e.g.:
TMP_CONTENT (or ID)
and replace with, e.g.:
NEW_CONTENT (or CNT_ID)
and click on Replace all.
7. Search for 'German' Umlauts
Mark the project and open Search/replace-dialog or Search all-dialog:
[^\000-\176]
search for all occurrences of characters which are not in the ASCII-range (octal: 0 - 176).
Click on Regexp and search. Be aware that each character
of each template-body is checked, so this might take a little while
and you should make sure that you won't search to many templates.