Skip to content

Commit

Permalink
Only set Find in Files directory once per-document
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ntrel committed Jul 26, 2012
1 parent 98452ed commit f90bdc5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
12 changes: 9 additions & 3 deletions doc/geany.html
Expand Up @@ -1704,6 +1704,8 @@ <h3><a class="toc-backref" href="#id67">Find in files</a></h3>
must be correctly set in Preferences to the path of the system's Grep
utility. GNU Grep is recommended (see note below).</p>
<img alt="./images/find_in_files_dialog.png" src="./images/find_in_files_dialog.png" />
<p>The <em>Search</em> field is initially set to the current word in the editor
(depending on <a class="reference internal" href="#search">Search</a> preferences).</p>
<p>The <em>Files</em> setting allows to choose which files are included in the
search, depending on the mode:</p>
<dl class="docutils">
Expand All @@ -1719,6 +1721,10 @@ <h3><a class="toc-backref" href="#id67">Find in files</a></h3>
use: <tt class="docutils literal">*.c *.h</tt>.
Note that an empty pattern list searches in all files rather
than none.</p>
<p>The <em>Directory</em> field is initially set to the current document's directory,
unless this field has already been edited and the current document has
not changed. Otherwise, the current document's directory is prepended to
the drop-down history. This can be disabled - see <a class="reference internal" href="#search">Search</a> preferences.</p>
<p>The <em>Encoding</em> field can be used to define the encoding of the files
to be searched. The entered search text is converted to the chosen encoding
and the search results are converted back to UTF-8.</p>
Expand Down Expand Up @@ -2218,9 +2224,9 @@ <h4><a class="toc-backref" href="#id94">Search</a></h4>
there is no selection. When this option is disabled, the search term last used in the
appropriate Find dialog is used.</dd>
<dt>Use the current file's directory for Find in Files</dt>
<dd>When opening the <a class="reference internal" href="#find-in-files">Find in Files</a> dialog, set the directory to search to the directory of the current
<dd>When opening the Find in Files dialog, set the directory to search to the directory of the current
active file. When this option is disabled, the directory of the last use of the Find in Files
dialog is used.</dd>
dialog is used. See <a class="reference internal" href="#find-in-files">Find in Files</a> for details.</dd>
</dl>
</div>
<div class="section" id="projects">
Expand Down Expand Up @@ -6797,7 +6803,7 @@ <h1><a class="toc-backref" href="#id245">License for Scintilla and SciTE</a></h1
<div class="footer">
<hr class="footer" />
<a class="reference external" href="geany.txt">View document source</a>.
Generated on: 2012-07-26 14:29 UTC.
Generated on: 2012-07-26 14:56 UTC.
Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.

</div>
Expand Down
12 changes: 10 additions & 2 deletions doc/geany.txt
Expand Up @@ -1277,6 +1277,9 @@ utility. GNU Grep is recommended (see note below).

.. image:: ./images/find_in_files_dialog.png

The *Search* field is initially set to the current word in the editor
(depending on `Search`_ preferences).

The *Files* setting allows to choose which files are included in the
search, depending on the mode:

Expand All @@ -1293,6 +1296,11 @@ use: ``*.c *.h``.
Note that an empty pattern list searches in all files rather
than none.

The *Directory* field is initially set to the current document's directory,
unless this field has already been edited and the current document has
not changed. Otherwise, the current document's directory is prepended to
the drop-down history. This can be disabled - see `Search`_ preferences.

The *Encoding* field can be used to define the encoding of the files
to be searched. The entered search text is converted to the chosen encoding
and the search results are converted back to UTF-8.
Expand Down Expand Up @@ -1829,9 +1837,9 @@ Use the current word under the cursor for Find dialogs
appropriate Find dialog is used.

Use the current file's directory for Find in Files
When opening the `Find in Files`_ dialog, set the directory to search to the directory of the current
When opening the Find in Files dialog, set the directory to search to the directory of the current
active file. When this option is disabled, the directory of the last use of the Find in Files
dialog is used.
dialog is used. See `Find in Files`_ for details.

Projects
````````
Expand Down
21 changes: 18 additions & 3 deletions src/search.c
Expand Up @@ -1073,12 +1073,27 @@ void search_show_find_in_files_dialog(const gchar *dir)
cur_dir = g_strdup(dir); /* custom directory argument passed */
else
{
gboolean entry_empty = ! NZV(gtk_entry_get_text(GTK_ENTRY(entry)));

if (search_prefs.use_current_file_dir || entry_empty)
if (search_prefs.use_current_file_dir)
{
static gchar *last_cur_dir = NULL;
static GeanyDocument *last_doc = NULL;

/* Only set the directory entry once for the current document */
cur_dir = utils_get_current_file_dir_utf8();
if (doc == last_doc && cur_dir && utils_str_equal(cur_dir, last_cur_dir))
{
/* in case the user now wants the current directory, add it to history */
ui_combo_box_add_to_history(
GTK_COMBO_BOX_ENTRY(fif_dlg.dir_combo), cur_dir, 0);
SETPTR(cur_dir, NULL);
}
else
SETPTR(last_cur_dir, g_strdup(cur_dir));

last_doc = doc;
}
if (!cur_dir && ! NZV(gtk_entry_get_text(GTK_ENTRY(entry))))
{
/* use default_open_path if no directory could be determined
* (e.g. when no files are open) */
if (!cur_dir)
Expand Down

0 comments on commit f90bdc5

Please sign in to comment.