[gnome-latex: 131/205] Find: under the source view instead of a dialog
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 131/205] Find: under the source view instead of a dialog
- Date: Fri, 14 Dec 2018 10:57:54 +0000 (UTC)
commit 51e54d1092bc62d594e8cb0403e029a934d25214
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sun Dec 6 01:49:37 2009 +0100
Find: under the source view instead of a dialog
TODO | 2 --
src/callbacks.c | 101 +++++++++++++++++++++++++++++---------------------------
src/callbacks.h | 6 +++-
src/main.c | 45 ++++++++++++++++++++++++-
src/main.h | 3 ++
5 files changed, 105 insertions(+), 52 deletions(-)
---
diff --git a/TODO b/TODO
index c9e4e11..a7e00c4 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,4 @@ TODO LaTeXila
[-] BibTeX support
-[x] color scheme
-
[-] search and replace like the Goto Line (under the source view)
diff --git a/src/callbacks.c b/src/callbacks.c
index 0cd2f90..ab407ce 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -50,6 +50,7 @@ static void set_title (void);
static void set_undo_redo_sensitivity (void);
static void update_cursor_position_statusbar (void);
static void scroll_to_cursor (void);
+static void find (gboolean backward);
static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
gboolean backward, GtkTextIter *match_start, GtkTextIter *match_end);
static void free_latexila (void);
@@ -347,59 +348,40 @@ cb_find (void)
if (latexila.active_doc == NULL)
return;
- GtkWidget *dialog = gtk_dialog_new_with_buttons (
- _("Find"),
- latexila.main_window,
- GTK_DIALOG_MODAL,
- GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
- GTK_STOCK_FIND, GTK_RESPONSE_OK,
- NULL);
-
- GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
- GtkWidget *hbox = gtk_hbox_new (FALSE, 10);
- GtkWidget *label = gtk_label_new (_("Search for:"));
- GtkWidget *entry = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 5);
-
- GtkWidget *case_sensitive = gtk_check_button_new_with_label (
- _("Case sensitive"));
- gtk_box_pack_start (GTK_BOX (content_area), case_sensitive, TRUE, TRUE, 5);
-
- GtkWidget *backward_search = gtk_check_button_new_with_label (
- _("Search backwards"));
- gtk_box_pack_start (GTK_BOX (content_area), backward_search, TRUE, TRUE, 5);
-
- gtk_widget_show_all (content_area);
+ gtk_widget_show_all (latexila.find);
+ gtk_widget_grab_focus (latexila.find_entry);
+}
- guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
- "searching");
+void
+cb_close_find (GtkWidget *widget, gpointer user_data)
+{
+ gtk_widget_hide (latexila.find);
- while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
- {
- const gchar *what = gtk_entry_get_text (GTK_ENTRY (entry));
- gboolean tmp = gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (case_sensitive));
- GtkSourceSearchFlags flags = tmp ? 0 : GTK_SOURCE_SEARCH_CASE_INSENSITIVE;
+ guint context_id = gtk_statusbar_get_context_id (latexila.statusbar, "find");
+ gtk_statusbar_pop (latexila.statusbar, context_id);
+
+ if (latexila.active_doc == NULL)
+ return;
- gboolean backward = gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (backward_search));
+ gtk_widget_grab_focus (latexila.active_doc->source_view);
+}
- GtkTextIter match_start, match_end;
- if (! find_next_match (what, flags, backward, &match_start, &match_end))
- {
- // print a message in the statusbar
- gtk_statusbar_pop (latexila.statusbar, context_id);
- gtk_statusbar_push (latexila.statusbar, context_id,
- _("Phrase not found"));
- }
- }
+void
+cb_find_entry (GtkEntry *entry, gpointer user_data)
+{
+ find (FALSE);
+}
- gtk_statusbar_pop (latexila.statusbar, context_id);
+void
+cb_find_next (GtkWidget *widget, gpointer user_data)
+{
+ find (FALSE);
+}
- gtk_widget_destroy (dialog);
+void
+cb_find_previous (GtkWidget *widget, gpointer user_data)
+{
+ find (TRUE);
}
void
@@ -568,7 +550,7 @@ cb_go_to_line (void)
}
void
-cb_close_go_to_line (GtkWidget *widget, GtkWidget *child)
+cb_close_go_to_line (GtkWidget *widget, gpointer user_data)
{
gtk_widget_hide (latexila.go_to_line);
@@ -1411,6 +1393,29 @@ scroll_to_cursor (void)
0.25, FALSE, 0, 0);
}
+static void
+find (gboolean backward)
+{
+ if (latexila.active_doc == NULL)
+ return;
+
+ guint context_id = gtk_statusbar_get_context_id (latexila.statusbar, "find");
+
+ const gchar *what = gtk_entry_get_text (GTK_ENTRY (latexila.find_entry));
+ gboolean tmp = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON (latexila.find_match_case));
+ GtkSourceSearchFlags flags = tmp ? 0 : GTK_SOURCE_SEARCH_CASE_INSENSITIVE;
+
+ GtkTextIter match_start, match_end;
+ if (! find_next_match (what, flags, backward, &match_start, &match_end))
+ {
+ // print a message in the statusbar
+ gtk_statusbar_pop (latexila.statusbar, context_id);
+ gtk_statusbar_push (latexila.statusbar, context_id,
+ _("Phrase not found"));
+ }
+}
+
static gboolean
find_next_match (const gchar *what, GtkSourceSearchFlags flags,
gboolean backward, GtkTextIter *match_start, GtkTextIter *match_end)
diff --git a/src/callbacks.h b/src/callbacks.h
index ff09ff5..798113a 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -38,9 +38,13 @@ void cb_zoom_in (void);
void cb_zoom_out (void);
void cb_zoom_reset (void);
void cb_find (void);
+void cb_close_find (GtkWidget *widget, gpointer user_data);
+void cb_find_entry (GtkEntry *entry, gpointer user_data);
+void cb_find_next (GtkWidget *widget, gpointer user_data);
+void cb_find_previous (GtkWidget *widget, gpointer user_data);
void cb_replace (void);
void cb_go_to_line (void);
-void cb_close_go_to_line (GtkWidget *widget, GtkWidget *child);
+void cb_close_go_to_line (GtkWidget *widget, gpointer user_data);
void cb_go_to_line_entry (GtkEntry *entry, gpointer user_data);
void cb_latex (void);
void cb_pdflatex (void);
diff --git a/src/main.c b/src/main.c
index ae11885..954dfd7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -205,7 +205,7 @@ main (int argc, char *argv[])
init_file_browser ();
/* vertical pane
- * top: source view and go to line
+ * top: source view, go to line, search and replace
* bottom: log zone
*/
GtkWidget *vpaned = gtk_vpaned_new ();
@@ -252,6 +252,48 @@ main (int argc, char *argv[])
G_CALLBACK (cb_go_to_line_entry), NULL);
gtk_box_pack_start (GTK_BOX (go_to_line), entry_go_to_line, FALSE, FALSE, 0);
+ /* find */
+ GtkWidget *find = gtk_hbox_new (FALSE, 3);
+ latexila.find = find;
+ gtk_box_pack_start (GTK_BOX (vbox_source_view), find, FALSE, FALSE, 0);
+
+ close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+ gtk_container_add (GTK_CONTAINER (close_button), image);
+ g_signal_connect (G_OBJECT (close_button), "clicked",
+ G_CALLBACK (cb_close_find), NULL);
+ gtk_box_pack_start (GTK_BOX (find), close_button, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Find:"));
+ gtk_box_pack_start (GTK_BOX (find), label, FALSE, FALSE, 2);
+
+ GtkWidget *find_entry = gtk_entry_new ();
+ latexila.find_entry = find_entry;
+ g_signal_connect (G_OBJECT (find_entry), "activate",
+ G_CALLBACK (cb_find_entry), NULL);
+ gtk_box_pack_start (GTK_BOX (find), find_entry, FALSE, FALSE, 0);
+
+ GtkWidget *previous_button = gtk_button_new_with_label (_("Previous"));
+ image = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (previous_button), image);
+ gtk_button_set_relief (GTK_BUTTON (previous_button), GTK_RELIEF_NONE);
+ g_signal_connect (G_OBJECT (previous_button), "clicked",
+ G_CALLBACK (cb_find_previous), NULL);
+ gtk_box_pack_start (GTK_BOX (find), previous_button, FALSE, FALSE, 0);
+
+ GtkWidget *next_button = gtk_button_new_with_label (_("Next"));
+ image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_MENU);
+ gtk_button_set_image (GTK_BUTTON (next_button), image);
+ gtk_button_set_relief (GTK_BUTTON (next_button), GTK_RELIEF_NONE);
+ g_signal_connect (G_OBJECT (next_button), "clicked",
+ G_CALLBACK (cb_find_next), NULL);
+ gtk_box_pack_start (GTK_BOX (find), next_button, FALSE, FALSE, 0);
+
+ GtkWidget *match_case = gtk_check_button_new_with_label (_("Match case"));
+ latexila.find_match_case = match_case;
+ gtk_box_pack_start (GTK_BOX (find), match_case, FALSE, FALSE, 0);
+
/* log zone */
// horizontal pane:
// left: action history
@@ -342,6 +384,7 @@ main (int argc, char *argv[])
gtk_widget_hide (latexila.edit_toolbar);
gtk_widget_hide (latexila.go_to_line);
+ gtk_widget_hide (latexila.find);
/* reopen files on startup */
gchar ** list_opened_docs = (gchar **) latexila.prefs.list_opened_docs->pdata;
diff --git a/src/main.h b/src/main.h
index c78a559..59d3e35 100644
--- a/src/main.h
+++ b/src/main.h
@@ -131,6 +131,9 @@ typedef struct
GtkWidget *side_pane;
GtkWidget *go_to_line;
GtkWidget *go_to_line_entry;
+ GtkWidget *find;
+ GtkWidget *find_entry;
+ GtkWidget *find_match_case;
} latexila_t;
// a lot of things are accessible by the "latexila" variable everywhere in the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]