[gnome-latex: 128/205] Search: Goto Line
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 128/205] Search: Goto Line
- Date: Fri, 14 Dec 2018 10:57:38 +0000 (UTC)
commit f03255dfbd6a4e8ea96966f4bc9e9fe73f7730ec
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sat Nov 28 14:39:53 2009 +0100
Search: Goto Line
TODO | 7 +------
src/callbacks.c | 32 ++++++++++++++++++++++++++++++++
src/callbacks.h | 3 +++
src/main.c | 35 +++++++++++++++++++++++++++++++++--
src/main.h | 2 ++
src/ui.c | 2 ++
src/ui.xml | 2 ++
7 files changed, 75 insertions(+), 8 deletions(-)
---
diff --git a/TODO b/TODO
index 8ebd5fc..bd2ab7c 100644
--- a/TODO
+++ b/TODO
@@ -8,9 +8,4 @@ TODO LaTeXila
[-] BibTeX support
-[x] Documents menu
- x close all
- x save all
- x previous/next document
-
-[-] Search -> Goto line
+[x] Search -> Goto line
diff --git a/src/callbacks.c b/src/callbacks.c
index 8e28c57..6ddeaa8 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -543,6 +543,38 @@ cb_replace (void)
gtk_widget_destroy (dialog);
}
+void
+cb_go_to_line (void)
+{
+ if (latexila.active_doc == NULL)
+ return;
+
+ gtk_widget_show_all (latexila.go_to_line);
+ gtk_widget_grab_focus (latexila.go_to_line_entry);
+}
+
+void
+cb_close_go_to_line (GtkWidget *widget, GtkWidget *child)
+{
+ gtk_widget_hide (latexila.go_to_line);
+}
+
+void
+cb_go_to_line_entry (GtkEntry *entry, gpointer user_data)
+{
+ if (latexila.active_doc == NULL)
+ return;
+
+ const gchar *txt = gtk_entry_get_text (entry);
+ gint num = strtol (txt, NULL, 10);
+ GtkTextIter iter;
+ GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+ gtk_text_buffer_get_iter_at_line (buffer, &iter, --num);
+ gtk_text_buffer_place_cursor (buffer, &iter);
+ scroll_to_cursor ();
+ gtk_widget_grab_focus (latexila.active_doc->source_view);
+}
+
gboolean
cb_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
diff --git a/src/callbacks.h b/src/callbacks.h
index 04dc584..ff09ff5 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -39,6 +39,9 @@ void cb_zoom_out (void);
void cb_zoom_reset (void);
void cb_find (void);
void cb_replace (void);
+void cb_go_to_line (void);
+void cb_close_go_to_line (GtkWidget *widget, GtkWidget *child);
+void cb_go_to_line_entry (GtkEntry *entry, gpointer user_data);
void cb_latex (void);
void cb_pdflatex (void);
void cb_view_dvi (void);
diff --git a/src/main.c b/src/main.c
index a66e697..8eb0200 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
+ * top: source view and go to line
* bottom: log zone
*/
GtkWidget *vpaned = gtk_vpaned_new ();
@@ -213,6 +213,9 @@ main (int argc, char *argv[])
gtk_paned_set_position (GTK_PANED (vpaned), latexila.prefs.vpaned_pos);
gtk_paned_add2 (GTK_PANED (main_hpaned), vpaned);
+ GtkWidget *vbox_source_view = gtk_vbox_new (FALSE, 2);
+ gtk_paned_add1 (GTK_PANED (vpaned), vbox_source_view);
+
/* source view with tabs */
GtkWidget *notebook = gtk_notebook_new ();
latexila.notebook = GTK_NOTEBOOK (notebook);
@@ -221,7 +224,33 @@ main (int argc, char *argv[])
G_CALLBACK (cb_page_change), NULL);
g_signal_connect (G_OBJECT (notebook), "page-reordered",
G_CALLBACK (cb_page_reordered), NULL);
- gtk_paned_add1 (GTK_PANED (vpaned), notebook);
+ gtk_box_pack_start (GTK_BOX (vbox_source_view), notebook, TRUE, TRUE, 0);
+
+ /* go to line */
+ GtkWidget *go_to_line = gtk_hbox_new (FALSE, 3);
+ latexila.go_to_line = go_to_line;
+ gtk_box_pack_start (GTK_BOX (vbox_source_view), go_to_line, FALSE, FALSE, 0);
+
+ GtkWidget *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_go_to_line), NULL);
+ gtk_box_pack_start (GTK_BOX (go_to_line), close_button, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Go to Line:"));
+ gtk_box_pack_start (GTK_BOX (go_to_line), label, FALSE, FALSE, 2);
+
+ GtkWidget *entry_go_to_line = gtk_entry_new ();
+ latexila.go_to_line_entry = entry_go_to_line;
+ gtk_entry_set_icon_from_stock (GTK_ENTRY (entry_go_to_line),
+ GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_JUMP_TO);
+ gtk_widget_set_tooltip_text (entry_go_to_line,
+ _("Line you want to move the cursor to"));
+ g_signal_connect (G_OBJECT (entry_go_to_line), "activate",
+ G_CALLBACK (cb_go_to_line_entry), NULL);
+ gtk_box_pack_start (GTK_BOX (go_to_line), entry_go_to_line, FALSE, FALSE, 0);
/* log zone */
// horizontal pane:
@@ -312,6 +341,8 @@ main (int argc, char *argv[])
if (! latexila.prefs.show_edit_toolbar)
gtk_widget_hide (latexila.edit_toolbar);
+ gtk_widget_hide (latexila.go_to_line);
+
/* reopen files on startup */
gchar ** list_opened_docs = (gchar **) latexila.prefs.list_opened_docs->pdata;
for (int i = 0 ; i < latexila.prefs.list_opened_docs->len
diff --git a/src/main.h b/src/main.h
index f8de3d8..4164f9b 100644
--- a/src/main.h
+++ b/src/main.h
@@ -128,6 +128,8 @@ typedef struct
GtkPaned *log_hpaned;
GtkWidget *edit_toolbar;
GtkWidget *side_pane;
+ GtkWidget *go_to_line;
+ GtkWidget *go_to_line_entry;
} latexila_t;
// a lot of things are accessible by the "latexila" variable everywhere in the
diff --git a/src/ui.c b/src/ui.c
index 5e5d30f..d403517 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -115,6 +115,8 @@ static GtkActionEntry entries[] = {
N_("Search for text"), G_CALLBACK (cb_find)},
{"SearchReplace", GTK_STOCK_FIND_AND_REPLACE, N_("Replace..."), "<Control>H",
N_("Search for and replace text"), G_CALLBACK (cb_replace)},
+ {"SearchGoToLine", GTK_STOCK_JUMP_TO, N_("Go to Line..."), "<Control>I",
+ N_("Go to a specific line"), G_CALLBACK (cb_go_to_line)},
{"Build", NULL, N_("Build"), NULL, NULL, NULL},
{"compile_latex", "compile_latex", N_("Compile (latex)"), "<Release>F5",
diff --git a/src/ui.xml b/src/ui.xml
index 9c9dec5..c6db81e 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -61,6 +61,8 @@ In the code, GtkUIManager is used to construct them.
<menu action="Search">
<menuitem action="SearchFind" />
<menuitem action="SearchReplace" />
+ <separator />
+ <menuitem action="SearchGoToLine" />
</menu>
<menu action="Build">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]