[gnome-latex: 27/205] statusbar: - print some text - show the row and the column of the cursor
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 27/205] statusbar: - print some text - show the row and the column of the cursor
- Date: Fri, 14 Dec 2018 10:49:09 +0000 (UTC)
commit 76cd6f550b29bfe1087cf8d519229cef50b2db73
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sun Aug 23 18:58:52 2009 +0200
statusbar:
- print some text
- show the row and the column of the cursor
TODO | 7 ++--
src/Makefile | 2 +-
src/callbacks.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++-------
src/callbacks.h | 2 ++
src/main.c | 12 ++++++-
src/main.h | 2 ++
6 files changed, 117 insertions(+), 18 deletions(-)
---
diff --git a/TODO b/TODO
index e0eb0f4..abda921 100644
--- a/TODO
+++ b/TODO
@@ -14,10 +14,9 @@ Tue Aug 18, 2009 to Mon Aug 24, 2009
[x] files recently opened (in the File menu)
-[-] statusbar
- - function print_statusbar ()
- - write some text in the statusbar
- - show which line and which column the cursor is
+[x] statusbar
+ x write some text in the statusbar
+ x show which line and which column the cursor is
[x] icons: PDF, DVI, ...
diff --git a/src/Makefile b/src/Makefile
index f41fb00..864cc18 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
CC = gcc
-CFLAGS = -g -Wall -std=c99 $(shell pkg-config --cflags gtk+-2.0 gtksourceview-2.0) -DGTK_DISABLE_DEPRECATED=1
+CFLAGS = -Wall -std=c99 $(shell pkg-config --cflags gtk+-2.0 gtksourceview-2.0) -DGTK_DISABLE_DEPRECATED=1
LDFLAGS = $(shell pkg-config --libs gtk+-2.0 gtksourceview-2.0)
OBJ = main.o callbacks.o print.o
diff --git a/src/callbacks.c b/src/callbacks.c
index ac22a99..b60dfd2 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -27,6 +27,7 @@ static void view_document (gchar *title, gchar *doc_extension);
static void convert_document (gchar *title, gchar *doc_extension,
gchar *command);
static void add_action (gchar *title, gchar *command, gchar *command_output);
+static void update_cursor_position_statusbar ();
void
cb_new (void)
@@ -146,6 +147,7 @@ cb_close_tab (GtkWidget *widget, GtkWidget *child)
latexila.active_doc = NULL;
set_undo_redo_sensitivity ();
+ update_cursor_position_statusbar ();
}
// the document to close is not the current document
@@ -318,14 +320,27 @@ cb_text_changed (GtkWidget *widget, gpointer user_data)
latexila.active_doc->saved = FALSE;
set_title ();
set_undo_redo_sensitivity ();
+
+ update_cursor_position_statusbar ();
}
}
+void
+cb_cursor_moved (GtkTextBuffer *text_buffer, GtkTextIter *location,
+ GtkTextMark *mark, gpointer user_data)
+{
+ if (mark != gtk_text_buffer_get_insert (text_buffer))
+ return;
+
+ update_cursor_position_statusbar ();
+}
+
void
cb_page_change (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data)
{
latexila.active_doc = g_list_nth_data (latexila.all_docs, page_num);
set_undo_redo_sensitivity ();
+ update_cursor_position_statusbar ();
}
void
@@ -419,10 +434,19 @@ create_document_in_new_tab (const gchar *path, const gchar *text, const gchar *t
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (new_doc->source_buffer), text, -1);
gtk_source_buffer_end_not_undoable_action (new_doc->source_buffer);
+ // move the cursor at the start
+ GtkTextIter start;
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (new_doc->source_buffer), &start);
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (new_doc->source_buffer), &start);
+
// when the text is modified
g_signal_connect (G_OBJECT (new_doc->source_buffer), "changed",
G_CALLBACK (cb_text_changed), NULL);
+ // when the cursor is moved
+ g_signal_connect (G_OBJECT (new_doc->source_buffer), "mark-set",
+ G_CALLBACK (cb_cursor_moved), NULL);
+
// with a scrollbar
GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
@@ -457,6 +481,7 @@ create_document_in_new_tab (const gchar *path, const gchar *text, const gchar *t
gtk_notebook_set_current_page (latexila.notebook, index);
set_undo_redo_sensitivity ();
+ update_cursor_position_statusbar ();
}
static void
@@ -634,8 +659,8 @@ run_compilation (gchar *title, gchar *command)
{
gchar *command_output;
- // the current document is a *.tex file?
- gboolean tex_file = g_regex_match_simple ("\\.tex$", latexila.active_doc->path, 0, 0);
+ /* the current document is a *.tex file? */
+ gboolean tex_file = g_str_has_suffix (latexila.active_doc->path, ".tex");
if (! tex_file)
{
command_output = g_strdup_printf (_("compilation failed: %s is not a *.tex file"),
@@ -646,7 +671,17 @@ run_compilation (gchar *title, gchar *command)
return;
}
- // run the command in the directory where the .tex is
+ /* print a message in the statusbar */
+ guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
+ "running-action");
+ gtk_statusbar_push (latexila.statusbar, context_id,
+ _("Compilation in progress. Please wait..."));
+
+ // without do that, the message in the statusbar does not appear
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ /* run the command in the directory where the .tex is */
gchar *dir_backup = g_get_current_dir ();
gchar *dir = g_path_get_dirname (latexila.active_doc->path);
g_chdir (dir);
@@ -667,6 +702,8 @@ run_compilation (gchar *title, gchar *command)
add_action (title, command, command_output);
+ gtk_statusbar_pop (latexila.statusbar, context_id);
+
g_free (command_output);
g_free (dir_backup);
g_free (dir);
@@ -683,13 +720,13 @@ view_document (gchar *title, gchar *doc_extension)
GError *error = NULL;
GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
- // replace .tex by doc_extension (.pdf, .dvi, ...)
+ /* replace .tex by doc_extension (.pdf, .dvi, ...) */
gchar *doc_path = g_regex_replace_literal (regex, latexila.active_doc->path,
-1, 0, doc_extension, 0, NULL);
command = g_strdup_printf ("evince %s", doc_path);
- // the current document is a *.tex file?
+ /* the current document is a *.tex file? */
gboolean tex_file = g_regex_match (regex, latexila.active_doc->path, 0, NULL);
if (! tex_file)
{
@@ -704,7 +741,7 @@ view_document (gchar *title, gchar *doc_extension)
return;
}
- // the document (PDF, DVI, ...) file exist?
+ /* the document (PDF, DVI, ...) file exist? */
if (! g_file_test (doc_path, G_FILE_TEST_IS_REGULAR))
{
command_output = g_strdup_printf (
@@ -719,7 +756,7 @@ view_document (gchar *title, gchar *doc_extension)
return;
}
- // run the command
+ /* run the command */
print_info ("execution of the command: %s", command);
g_spawn_command_line_async (command, &error);
@@ -730,7 +767,7 @@ view_document (gchar *title, gchar *doc_extension)
g_error_free (error);
}
else
- command_output = g_strdup ("OK");
+ command_output = g_strdup (_("Viewing in progress. Please wait..."));
add_action (title, command, command_output);
@@ -751,13 +788,13 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
GError *error = NULL;
GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
- // replace .tex by doc_extension (.pdf, .dvi, ...)
+ /* replace .tex by doc_extension (.pdf, .dvi, ...) */
gchar *doc_path = g_regex_replace_literal (regex,
latexila.active_doc->path, -1, 0, doc_extension, 0, NULL);
full_command = g_strdup_printf ("%s %s", command, doc_path);
- // the document to convert exist?
+ /* the document to convert exist? */
if (! g_file_test (doc_path, G_FILE_TEST_IS_REGULAR))
{
command_output = g_strdup_printf (
@@ -772,7 +809,17 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
return;
}
- // run the command in the directory where the .tex is
+ /* print a message in the statusbar */
+ guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
+ "running-action");
+ gtk_statusbar_push (latexila.statusbar, context_id,
+ _("Converting in progress. Please wait..."));
+
+ // without do that, the message in the statusbar does not appear
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ /* run the command in the directory where the .tex is */
print_info ("execution of the command: %s", full_command);
gchar *dir_backup = g_get_current_dir ();
@@ -780,7 +827,6 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
g_chdir (dir);
g_spawn_command_line_sync (full_command, &command_output, NULL, NULL, &error);
g_chdir (dir_backup);
-
// an error occured
if (error != NULL)
@@ -792,6 +838,8 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
add_action (title, full_command, command_output);
+ gtk_statusbar_pop (latexila.statusbar, context_id);
+
g_free (full_command);
g_free (command_output);
g_free (doc_path);
@@ -827,4 +875,42 @@ add_action (gchar *title, gchar *command, gchar *command_output)
g_free (title2);
}
+static void
+update_cursor_position_statusbar ()
+{
+ /* get the cursor location */
+ GtkTextIter location;
+ GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &location,
+ gtk_text_buffer_get_insert (buffer));
+
+ /* get row */
+ gint row = gtk_text_iter_get_line (&location) + 1;
+
+ /* get column */
+ gint tabwidth = gtk_source_view_get_tab_width (
+ GTK_SOURCE_VIEW (latexila.active_doc->source_view));
+ GtkTextIter start = location;
+ gtk_text_iter_set_line_offset (&start, 0);
+ gint col = 1;
+
+ while (!gtk_text_iter_equal (&start, &location))
+ {
+ // take into acount the tabulation width
+ if (gtk_text_iter_get_char (&start) == '\t')
+ {
+ col += (tabwidth - (col % tabwidth));
+ }
+ else
+ col++;
+
+ gtk_text_iter_forward_char (&start);
+ }
+
+ /* print the cursor position in the statusbar */
+ gtk_statusbar_pop (latexila.cursor_position, 0);
+ gchar *text = g_strdup_printf ("Ln %d, Col %d", row, col);
+ gtk_statusbar_push (latexila.cursor_position, 0, text);
+ g_free (text);
+}
diff --git a/src/callbacks.h b/src/callbacks.h
index 8263cbe..2a340b1 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -21,6 +21,8 @@ void cb_action_list_changed (GtkTreeSelection *selection,
gpointer user_data);
void cb_about_dialog (void);
void cb_text_changed (GtkWidget *widget, gpointer user_data);
+void cb_cursor_moved (GtkTextBuffer *text_buffer, GtkTextIter *location,
+ GtkTextMark *mark, gpointer user_data);
void cb_page_change (GtkNotebook *notebook, GtkNotebookPage *page,
guint page_num, gpointer user_data);
gboolean cb_delete_event (GtkWidget *widget, GdkEvent *event,
diff --git a/src/main.c b/src/main.c
index 273ba21..246cc79 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,7 +11,8 @@
#include "callbacks.h"
#include "print.h"
-latexila_t latexila = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+latexila_t latexila = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL};
static struct {
gchar *filename;
@@ -260,8 +261,17 @@ main (int argc, char *argv[])
/* statusbar */
GtkWidget *statusbar = gtk_statusbar_new ();
+ latexila.statusbar = GTK_STATUSBAR (statusbar);
gtk_box_pack_start (GTK_BOX (main_vbox), statusbar, FALSE, FALSE, 0);
+ GtkWidget *cursor_position_statusbar = gtk_statusbar_new ();
+ latexila.cursor_position = GTK_STATUSBAR (cursor_position_statusbar);
+ gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (cursor_position_statusbar),
+ FALSE);
+ gtk_widget_set_size_request (cursor_position_statusbar, 150, -1);
+ gtk_box_pack_end (GTK_BOX (statusbar), cursor_position_statusbar,
+ FALSE, TRUE, 0);
+
gtk_widget_show_all (window);
gtk_main ();
diff --git a/src/main.h b/src/main.h
index 884a914..865af37 100644
--- a/src/main.h
+++ b/src/main.h
@@ -30,6 +30,8 @@ typedef struct
GtkTreeView *list_view;
GtkTreeSelection *list_selection;
GtkTextView *log;
+ GtkStatusbar *statusbar;
+ GtkStatusbar *cursor_position;
GtkAction *undo;
GtkAction *redo;
} latexila_t;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]