Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Find in Selection dialog button #3819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions doc/geany.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,15 @@ several options:

* In Document
* In Session
* Mark
* In Selection

Find All In Document will show a list of matching lines in the
*Find All In Document* will show a list of matching lines in the
current document in the Messages tab of the Message Window. *Find All
In Session* does the same for all open documents.
In Session* does the same for all open documents. *Find All In Selection* will
find all matching text in the current selection of the current document.

Mark will highlight all matches in the current document with a
There is also a Mark All button.
This will highlight all matches in the current document with a
colored box. These markers can be removed by selecting the
Remove Markers command from the Document menu.

Expand Down
8 changes: 4 additions & 4 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ static void on_use_auto_indentation1_toggled(GtkCheckMenuItem *checkmenuitem, gp
}


static void find_usage(gboolean in_session)
static void find_usage(GeanySearchResponse scope)
{
GeanyFindFlags flags;
gchar *search_text;
Expand All @@ -839,20 +839,20 @@ static void find_usage(gboolean in_session)
flags = GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD;
}

search_find_usage(search_text, search_text, flags, in_session);
search_find_usage(search_text, search_text, flags, scope);
g_free(search_text);
}


void on_find_document_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
find_usage(FALSE);
find_usage(GEANY_RESPONSE_FIND_IN_FILE);
}


void on_find_usage1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
find_usage(TRUE);
find_usage(GEANY_RESPONSE_FIND_IN_SESSION);
}


Expand Down
69 changes: 34 additions & 35 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

enum
{
GEANY_RESPONSE_FIND = 1,
GEANY_RESPONSE_FIND_PREVIOUS,
GEANY_RESPONSE_FIND_IN_FILE,
GEANY_RESPONSE_FIND_IN_SESSION,
GEANY_RESPONSE_MARK,
GEANY_RESPONSE_REPLACE,
GEANY_RESPONSE_REPLACE_AND_FIND,
GEANY_RESPONSE_REPLACE_IN_SESSION,
GEANY_RESPONSE_REPLACE_IN_FILE,
GEANY_RESPONSE_REPLACE_IN_SEL
};


enum
{
FILES_MODE_ALL,
Expand Down Expand Up @@ -473,6 +458,12 @@ static void create_find_dialog(void)
gtk_widget_set_name(find_dlg.dialog, "GeanyDialogSearch");
gtk_box_set_spacing(GTK_BOX(vbox), 9);

button = gtk_button_new_with_mnemonic(_("_Mark All"));
gtk_widget_set_tooltip_text(button,
_("Mark all matches in the current document"));
gtk_dialog_add_action_widget(GTK_DIALOG(find_dlg.dialog), button,
GEANY_RESPONSE_MARK);

button = ui_button_new_with_image(GTK_STOCK_GO_BACK, _("_Previous"));
gtk_dialog_add_action_widget(GTK_DIALOG(find_dlg.dialog), button,
GEANY_RESPONSE_FIND_PREVIOUS);
Expand Down Expand Up @@ -517,13 +508,6 @@ static void create_find_dialog(void)

bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);

button = gtk_button_new_with_mnemonic(_("_Mark"));
gtk_widget_set_tooltip_text(button,
_("Mark all matches in the current document"));
gtk_container_add(GTK_CONTAINER(bbox), button);
g_signal_connect(button, "clicked", G_CALLBACK(send_find_dialog_response),
GINT_TO_POINTER(GEANY_RESPONSE_MARK));

button = gtk_button_new_with_mnemonic(_("In Sessi_on"));
gtk_container_add(GTK_CONTAINER(bbox), button);
g_signal_connect(button, "clicked", G_CALLBACK(send_find_dialog_response),
Expand All @@ -534,6 +518,11 @@ static void create_find_dialog(void)
g_signal_connect(button, "clicked", G_CALLBACK(send_find_dialog_response),
GINT_TO_POINTER(GEANY_RESPONSE_FIND_IN_FILE));

button = gtk_button_new_with_mnemonic(_("In Se_lection"));
gtk_container_add(GTK_CONTAINER(bbox), button);
g_signal_connect(button, "clicked", G_CALLBACK(send_find_dialog_response),
GINT_TO_POINTER(GEANY_RESPONSE_FIND_IN_SEL));

/* close window checkbox */
check_close = gtk_check_button_new_with_mnemonic(_("Close _dialog"));
ui_hookup_widget(find_dlg.dialog, check_close, "check_close");
Expand Down Expand Up @@ -1358,12 +1347,10 @@ on_find_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
check_close = search_prefs.hide_find_dialog;
break;
}
case GEANY_RESPONSE_FIND_IN_FILE:
search_find_usage(search_data.text, search_data.original_text, search_data.flags, FALSE);
break;

case GEANY_RESPONSE_FIND_IN_SESSION:
search_find_usage(search_data.text, search_data.original_text, search_data.flags, TRUE);
case GEANY_RESPONSE_FIND_IN_FILE:
case GEANY_RESPONSE_FIND_IN_SEL:
search_find_usage(search_data.text, search_data.original_text, search_data.flags, response);
break;

case GEANY_RESPONSE_MARK:
Expand Down Expand Up @@ -2160,7 +2147,9 @@ gint search_find_text(ScintillaObject *sci, GeanyFindFlags flags, struct Sci_Tex
}


static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, GeanyFindFlags flags)
// range can be NULL
static gint find_document_usage(GeanyDocument *doc, const gchar *search_text,
GeanyFindFlags flags, struct Sci_CharacterRange *range)
{
gchar *buffer, *short_file_name;
struct Sci_TextToFind ttf;
Expand All @@ -2172,8 +2161,13 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, Ge

short_file_name = g_path_get_basename(DOC_FILENAME(doc));

ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(doc->editor->sci);
if (range)
ttf.chrg = *range;
else
{
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(doc->editor->sci);
}
ttf.lpstrText = (gchar *)search_text;

matches = find_range(doc->editor->sci, flags, &ttf);
Expand Down Expand Up @@ -2201,7 +2195,7 @@ static gint find_document_usage(GeanyDocument *doc, const gchar *search_text, Ge


void search_find_usage(const gchar *search_text, const gchar *original_search_text,
GeanyFindFlags flags, gboolean in_session)
GeanyFindFlags flags, GeanySearchResponse scope)
{
GeanyDocument *doc;
gint count = 0;
Expand All @@ -2218,18 +2212,23 @@ void search_find_usage(const gchar *search_text, const gchar *original_search_te
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_MESSAGE);
gtk_list_store_clear(msgwindow.store_msg);

if (! in_session)
{ /* use current document */
count = find_document_usage(doc, search_text, flags);
if (scope == GEANY_RESPONSE_FIND_IN_SEL)
{
struct Sci_CharacterRange range;
range.cpMin = sci_get_selection_start(doc->editor->sci);
range.cpMax = sci_get_selection_end(doc->editor->sci);
count = find_document_usage(doc, search_text, flags, &range);
}
else if (scope == GEANY_RESPONSE_FIND_IN_FILE)
count = find_document_usage(doc, search_text, flags, NULL);
else
{
guint i;
for (i = 0; i < documents_array->len; i++)
{
if (documents[i]->is_valid)
{
count += find_document_usage(documents[i], search_text, flags);
count += find_document_usage(documents[i], search_text, flags, NULL);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ extern GeanySearchData search_data;
extern GeanySearchPrefs search_prefs;


typedef enum
{
GEANY_RESPONSE_FIND = 1,
GEANY_RESPONSE_FIND_PREVIOUS,
GEANY_RESPONSE_FIND_IN_FILE,
GEANY_RESPONSE_FIND_IN_SESSION,
GEANY_RESPONSE_FIND_IN_SEL,
GEANY_RESPONSE_MARK,
GEANY_RESPONSE_REPLACE,
GEANY_RESPONSE_REPLACE_AND_FIND,
GEANY_RESPONSE_REPLACE_IN_SESSION,
GEANY_RESPONSE_REPLACE_IN_FILE,
GEANY_RESPONSE_REPLACE_IN_SEL
}
GeanySearchResponse;


void search_init(void);

void search_finalize(void);
Expand All @@ -128,7 +145,8 @@ gint search_find_text(struct _ScintillaObject *sci, GeanyFindFlags flags, struct

void search_find_again(gboolean change_direction);

void search_find_usage(const gchar *search_text, const gchar *original_search_text, GeanyFindFlags flags, gboolean in_session);
void search_find_usage(const gchar *search_text, const gchar *original_search_text,
GeanyFindFlags flags, GeanySearchResponse scope);

void search_find_selection(struct GeanyDocument *doc, gboolean search_backwards);

Expand Down
3 changes: 2 additions & 1 deletion src/symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,8 @@ static void on_find_usage(GtkWidget *widget, G_GNUC_UNUSED gpointer unused)
search_show_find_in_files_dialog_full(tag->name, NULL);
else
search_find_usage(tag->name, tag->name, GEANY_FIND_WHOLEWORD | GEANY_FIND_MATCHCASE,
widget == symbol_menu.find_usage);
widget == symbol_menu.find_usage ?
GEANY_RESPONSE_FIND_IN_SESSION : GEANY_RESPONSE_FIND_IN_FILE);

tm_tag_unref(tag);
}
Expand Down