[gnome-latex: 21/205] log zone: - horizontal pane with an action list and a text view for the details - default size
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 21/205] log zone: - horizontal pane with an action list and a text view for the details - default size
- Date: Fri, 14 Dec 2018 10:48:39 +0000 (UTC)
commit 84a9bce7b63ed8a9a1e72a91ff5f4c4fb6e42986
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Tue Aug 18 23:32:01 2009 +0200
log zone:
- horizontal pane with an action list and a text view for the
details
- default size
docs -> latexila (the extern variable containing a lot of things)
the actions are stored in latexila.all_actions, which is a GList of
action_t structures.
TODO | 4 +-
src/Makefile | 8 +-
src/callbacks.c | 292 ++++++++++++++++++++++++++++-------------------
src/error.c | 34 ------
src/main.c | 53 ++++++---
src/main.h | 46 +++++---
src/print.c | 68 +++++++++++
src/{error.h => print.h} | 18 +--
8 files changed, 326 insertions(+), 197 deletions(-)
---
diff --git a/TODO b/TODO
index 902e8f5..842c542 100644
--- a/TODO
+++ b/TODO
@@ -8,8 +8,8 @@ Tue Aug 18, 2009 to Mon Aug 24, 2009
- horizontal pane
left: list with an history of the actions numbered
right: details of the action selected
- - function print_log ()
- - default height and width
+ x function print_log ()
+ x default height and width
[-] statusbar
- function print_statusbar ()
diff --git a/src/Makefile b/src/Makefile
index 559b26b..f41fb00 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,18 +1,18 @@
CC = gcc
CFLAGS = -g -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 error.o
+OBJ = main.o callbacks.o print.o
.PHONY: clean
latexila: $(OBJ)
$(CC) $(OBJ) $(LDFLAGS) -o latexila
-main.o: main.c main.h callbacks.h error.h
+main.o: main.c main.h callbacks.h print.h
-callbacks.o: callbacks.c callbacks.h main.h error.h
+callbacks.o: callbacks.c callbacks.h main.h print.h
-error.o: error.c error.h
+print.o: print.c print.h main.h
clean:
rm -f $(OBJ) latexila
diff --git a/src/callbacks.c b/src/callbacks.c
index 6e0a389..4297e5b 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -11,7 +11,7 @@
#include "main.h"
#include "callbacks.h"
-#include "error.h"
+#include "print.h"
static void create_document_in_new_tab (gchar *path, gchar *text, gchar *title);
static void close_document (gint index);
@@ -20,8 +20,9 @@ static void file_save (void);
static gboolean close_all (void);
static void set_title (void);
static void set_undo_redo_sensitivity (void);
-static void run_compilation (gchar *command);
-static void view_document (gchar *doc_type, gchar *doc_extension);
+static void run_compilation (action_t *action);
+static void view_document (action_t *action, gchar *doc_extension);
+static void free_actions (void);
void
cb_new (void)
@@ -38,7 +39,7 @@ cb_open (void)
{
GtkWidget *dialog = gtk_file_chooser_dialog_new (
_("Open File"),
- docs.main_window,
+ latexila.main_window,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
@@ -71,11 +72,11 @@ cb_open (void)
void
cb_save (void)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- if (! docs.active->saved)
+ if (! latexila.active_doc->saved)
{
- if (docs.active->path == NULL)
+ if (latexila.active_doc->path == NULL)
save_as_dialog ();
file_save ();
@@ -90,17 +91,17 @@ cb_save (void)
void
cb_save_as (void)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- document_t doc_backup = *docs.active;
+ document_t doc_backup = *latexila.active_doc;
- docs.active->path = NULL;
- docs.active->saved = FALSE;
+ latexila.active_doc->path = NULL;
+ latexila.active_doc->saved = FALSE;
cb_save ();
// if the user click on cancel
- if (! docs.active->saved)
- (*docs.active) = doc_backup;
+ if (! latexila.active_doc->saved)
+ (*latexila.active_doc) = doc_backup;
}
else
@@ -110,15 +111,16 @@ cb_save_as (void)
void
cb_close (void)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- gint index = gtk_notebook_get_current_page (docs.notebook);
+ gint index = gtk_notebook_get_current_page (latexila.notebook);
close_document (index);
- if (gtk_notebook_get_n_pages (docs.notebook) > 0)
- docs.active = g_list_nth_data (docs.all, gtk_notebook_get_current_page
(docs.notebook));
+ if (gtk_notebook_get_n_pages (latexila.notebook) > 0)
+ latexila.active_doc = g_list_nth_data (latexila.all_docs,
+ gtk_notebook_get_current_page (latexila.notebook));
else
- docs.active = NULL;
+ latexila.active_doc = NULL;
set_undo_redo_sensitivity ();
}
@@ -130,19 +132,19 @@ cb_close (void)
void
cb_close_tab (GtkWidget *widget, GtkWidget *child)
{
- document_t *doc_backup = docs.active;
- gint page_to_close = gtk_notebook_page_num (docs.notebook, child);
- docs.active = g_list_nth_data (docs.all, page_to_close);
+ document_t *doc_backup = latexila.active_doc;
+ gint page_to_close = gtk_notebook_page_num (latexila.notebook, child);
+ latexila.active_doc = g_list_nth_data (latexila.all_docs, page_to_close);
// the document to close is the current document
- if (docs.active == doc_backup)
+ if (latexila.active_doc == doc_backup)
{
close_document (page_to_close);
- if (gtk_notebook_get_n_pages (docs.notebook) > 0)
- docs.active = g_list_nth_data (docs.all, gtk_notebook_get_current_page
(docs.notebook));
+ if (gtk_notebook_get_n_pages (latexila.notebook) > 0)
+ latexila.active_doc = g_list_nth_data (latexila.all_docs,
gtk_notebook_get_current_page (latexila.notebook));
else
- docs.active = NULL;
+ latexila.active_doc = NULL;
set_undo_redo_sensitivity ();
}
@@ -151,7 +153,7 @@ cb_close_tab (GtkWidget *widget, GtkWidget *child)
else
{
close_document (page_to_close);
- docs.active = doc_backup;
+ latexila.active_doc = doc_backup;
}
}
@@ -160,6 +162,7 @@ cb_quit (void)
{
if (close_all ())
{
+ free_actions ();
print_info ("Bye bye");
gtk_main_quit ();
}
@@ -168,8 +171,8 @@ cb_quit (void)
void
cb_undo (void)
{
- if (gtk_source_buffer_can_undo (docs.active->source_buffer))
- gtk_source_buffer_undo (docs.active->source_buffer);
+ if (gtk_source_buffer_can_undo (latexila.active_doc->source_buffer))
+ gtk_source_buffer_undo (latexila.active_doc->source_buffer);
set_undo_redo_sensitivity ();
}
@@ -177,8 +180,8 @@ cb_undo (void)
void
cb_redo (void)
{
- if (gtk_source_buffer_can_redo (docs.active->source_buffer))
- gtk_source_buffer_redo (docs.active->source_buffer);
+ if (gtk_source_buffer_can_redo (latexila.active_doc->source_buffer))
+ gtk_source_buffer_redo (latexila.active_doc->source_buffer);
set_undo_redo_sensitivity ();
}
@@ -198,10 +201,10 @@ cb_line_numbers (GtkToggleAction *action, gpointer user_data)
gboolean show = gtk_toggle_action_get_active (action);
//TODO optimisation?
- guint nb_docs = g_list_length (docs.all);
+ guint nb_docs = g_list_length (latexila.all_docs);
for (guint i = 0 ; i < nb_docs ; i++)
{
- document_t *doc = g_list_nth_data (docs.all, i);
+ document_t *doc = g_list_nth_data (latexila.all_docs, i);
gtk_source_view_set_show_line_numbers (
GTK_SOURCE_VIEW (doc->source_view), show);
}
@@ -210,25 +213,59 @@ cb_line_numbers (GtkToggleAction *action, gpointer user_data)
void
cb_latex (void)
{
- run_compilation ("latex -interaction=nonstopmode");
+ action_t *action = g_malloc (sizeof (action_t));
+ action->title = g_strdup (_("Compile (latex)"));
+ action->command = g_strdup_printf ("latex -interaction=nonstopmode %s",
+ latexila.active_doc->path);
+ action->command_output = NULL;
+
+ latexila.all_actions = g_list_append (latexila.all_actions, action);
+ latexila.active_action = action;
+
+ run_compilation (action);
}
void
cb_pdflatex (void)
{
- run_compilation ("pdflatex -interaction=nonstopmode");
+ action_t *action = g_malloc (sizeof (action_t));
+ action->title = g_strdup (_("Compile (pdflatex)"));
+ action->command = g_strdup_printf ("pdflatex -interaction=nonstopmode %s",
+ latexila.active_doc->path);
+ action->command_output = NULL;
+
+ latexila.all_actions = g_list_append (latexila.all_actions, action);
+ latexila.active_action = action;
+
+ run_compilation (action);
}
void
cb_view_dvi (void)
{
- view_document ("DVI", ".dvi");
+ action_t *action = g_malloc (sizeof (action_t));
+ action->title = g_strdup (_("View DVI"));
+ action->command = NULL;
+ action->command_output = NULL;
+
+ latexila.all_actions = g_list_append (latexila.all_actions, action);
+ latexila.active_action = action;
+
+ view_document (action, ".dvi");
}
void
cb_view_pdf (void)
{
- view_document ("PDF", ".pdf");
+ action_t *action = g_malloc (sizeof (action_t));
+ action->title = g_strdup (_("View PDF"));
+ action->command = NULL;
+ action->command_output = NULL;
+
+ latexila.all_actions = g_list_append (latexila.all_actions, action);
+ latexila.active_action = action;
+
+ view_document (action, ".pdf");
}
void
@@ -250,7 +287,7 @@ cb_about_dialog (void)
};
gtk_show_about_dialog (
- docs.main_window,
+ latexila.main_window,
"program-name", PROGRAM_NAME,
"authors", authors,
"comments", comments,
@@ -267,9 +304,9 @@ cb_about_dialog (void)
void
cb_text_changed (GtkWidget *widget, gpointer user_data)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- docs.active->saved = FALSE;
+ latexila.active_doc->saved = FALSE;
set_title ();
set_undo_redo_sensitivity ();
}
@@ -278,7 +315,7 @@ cb_text_changed (GtkWidget *widget, gpointer user_data)
void
cb_page_change (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data)
{
- docs.active = g_list_nth_data (docs.all, page_num);
+ latexila.active_doc = g_list_nth_data (latexila.all_docs, page_num);
set_undo_redo_sensitivity ();
}
@@ -299,14 +336,16 @@ create_document_in_new_tab (gchar *path, gchar *text, gchar *title)
new_doc->source_buffer = gtk_source_buffer_new (NULL);
new_doc->source_view = gtk_source_view_new_with_buffer (new_doc->source_buffer);
- docs.all = g_list_append (docs.all, new_doc);
- docs.active = new_doc;
+ latexila.all_docs = g_list_append (latexila.all_docs, new_doc);
+ latexila.active_doc = new_doc;
+
+ GtkSourceLanguageManager *lm = gtk_source_language_manager_get_default ();
// set the language for the syntaxic color
if (path != NULL)
{
GtkSourceLanguage *lang = gtk_source_language_manager_guess_language (
- docs.lm, path, NULL);
+ lm, path, NULL);
if (lang != NULL)
gtk_source_buffer_set_language (new_doc->source_buffer, lang);
else
@@ -317,7 +356,7 @@ create_document_in_new_tab (gchar *path, gchar *text, gchar *title)
else
{
GtkSourceLanguage *lang = gtk_source_language_manager_get_language (
- docs.lm, "latex");
+ lm, "latex");
gtk_source_buffer_set_language (new_doc->source_buffer, lang);
}
@@ -362,8 +401,8 @@ create_document_in_new_tab (gchar *path, gchar *text, gchar *title)
gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
gtk_widget_show_all (hbox);
- gint index = gtk_notebook_append_page (docs.notebook, sw, hbox);
- gtk_notebook_set_current_page (docs.notebook, index);
+ gint index = gtk_notebook_append_page (latexila.notebook, sw, hbox);
+ gtk_notebook_set_current_page (latexila.notebook, index);
set_undo_redo_sensitivity ();
}
@@ -371,15 +410,15 @@ create_document_in_new_tab (gchar *path, gchar *text, gchar *title)
static void
close_document (gint index)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
/* if the document is not saved, ask the user for saving changes before
* closing */
- if (! docs.active->saved)
+ if (! latexila.active_doc->saved)
{
GtkWidget *dialog = gtk_dialog_new_with_buttons (
_("Close the document"),
- docs.main_window,
+ latexila.main_window,
GTK_DIALOG_MODAL,
GTK_STOCK_YES, GTK_RESPONSE_YES,
GTK_STOCK_NO, GTK_RESPONSE_NO,
@@ -411,15 +450,15 @@ close_document (gint index)
}
/* close the tab */
- docs.all = g_list_remove (docs.all, docs.active);
- if (docs.active->path != NULL)
+ latexila.all_docs = g_list_remove (latexila.all_docs, latexila.active_doc);
+ if (latexila.active_doc->path != NULL)
{
- print_info ("close the file \"%s\"", docs.active->path);
- g_free (docs.active->path);
+ print_info ("close the file \"%s\"", latexila.active_doc->path);
+ g_free (latexila.active_doc->path);
}
- g_free (docs.active);
+ g_free (latexila.active_doc);
- gtk_notebook_remove_page (docs.notebook, index);
+ gtk_notebook_remove_page (latexila.notebook, index);
}
else
@@ -431,7 +470,7 @@ save_as_dialog (void)
{
GtkWidget *dialog = gtk_file_chooser_dialog_new (
_("Save File"),
- docs.main_window,
+ latexila.main_window,
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
@@ -439,7 +478,7 @@ save_as_dialog (void)
);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
- docs.active->path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ latexila.active_doc->path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
gtk_widget_destroy (dialog);
}
@@ -447,14 +486,14 @@ save_as_dialog (void)
static void
file_save (void)
{
- if (docs.active->path != NULL)
+ if (latexila.active_doc->path != NULL)
{
- print_info ("save current buffer to \"%s\"", docs.active->path);
+ print_info ("save current buffer to \"%s\"", latexila.active_doc->path);
- FILE* file = fopen (docs.active->path, "w");
+ FILE* file = fopen (latexila.active_doc->path, "w");
if (file != NULL)
{
- GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (docs.active->source_buffer);
+ GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
GtkTextIter start;
GtkTextIter end;
gtk_text_buffer_get_bounds (text_buffer, &start, &end);
@@ -468,14 +507,14 @@ file_save (void)
g_free (contents);
g_free (locale);
- docs.active->saved = TRUE;
+ latexila.active_doc->saved = TRUE;
}
// error with fopen
else
{
print_warning ("impossible to save the file \"%s\"",
- docs.active->path);
+ latexila.active_doc->path);
}
}
}
@@ -483,12 +522,12 @@ file_save (void)
static gboolean
close_all (void)
{
- while (docs.active != NULL)
+ while (latexila.active_doc != NULL)
{
- int tmp = gtk_notebook_get_n_pages (docs.notebook);
- gtk_notebook_set_current_page (docs.notebook, 0);
+ int tmp = gtk_notebook_get_n_pages (latexila.notebook);
+ gtk_notebook_set_current_page (latexila.notebook, 0);
cb_close ();
- if (gtk_notebook_get_n_pages (docs.notebook) >= tmp)
+ if (gtk_notebook_get_n_pages (latexila.notebook) >= tmp)
return FALSE;
}
@@ -498,22 +537,22 @@ close_all (void)
static void
set_title (void)
{
- if (docs.active)
+ if (latexila.active_doc)
{
gchar *tmp;
gchar *title;
- if (docs.active->path != NULL)
- tmp = g_path_get_basename (docs.active->path);
+ if (latexila.active_doc->path != NULL)
+ tmp = g_path_get_basename (latexila.active_doc->path);
else
tmp = g_strdup (_("New document"));
- if (docs.active->saved)
+ if (latexila.active_doc->saved)
title = g_strdup (tmp);
else
title = g_strdup_printf ("*%s", tmp);
- gtk_label_set_text (GTK_LABEL (docs.active->title), title);
+ gtk_label_set_text (GTK_LABEL (latexila.active_doc->title), title);
g_free (tmp);
g_free (title);
@@ -526,121 +565,134 @@ set_undo_redo_sensitivity (void)
gboolean can_undo = FALSE;
gboolean can_redo = FALSE;
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- can_undo = gtk_source_buffer_can_undo (docs.active->source_buffer);
- can_redo = gtk_source_buffer_can_redo (docs.active->source_buffer);
+ can_undo = gtk_source_buffer_can_undo (latexila.active_doc->source_buffer);
+ can_redo = gtk_source_buffer_can_redo (latexila.active_doc->source_buffer);
}
- gtk_action_set_sensitive (docs.undo, can_undo);
- gtk_action_set_sensitive (docs.redo, can_redo);
+ gtk_action_set_sensitive (latexila.undo, can_undo);
+ gtk_action_set_sensitive (latexila.redo, can_redo);
}
static void
-run_compilation (gchar *command)
+run_compilation (action_t *action)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
-
// the current document is a *.tex file?
- gboolean tex_file = g_regex_match_simple ("\\.tex$", docs.active->path, 0, 0);
+ gboolean tex_file = g_regex_match_simple ("\\.tex$", latexila.active_doc->path, 0, 0);
if (! tex_file)
{
- gchar *text = g_strdup_printf (_("compilation failed: %s is not a *.tex file"),
- g_path_get_basename (docs.active->path));
-
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
+ action->command_output = g_strdup_printf (_("compilation failed: %s is not a *.tex
file"),
+ g_path_get_basename (latexila.active_doc->path));
+ print_log (action);
return;
}
// run the command in the directory where the .tex is
gchar *dir_backup = g_get_current_dir ();
- gchar *dir = g_path_get_dirname (docs.active->path);
+ gchar *dir = g_path_get_dirname (latexila.active_doc->path);
g_chdir (dir);
- gchar *full_command = g_strdup_printf ("%s %s", command, docs.active->path);
- gchar *output;
+ //gchar *full_command = g_strdup_printf ("%s %s", command, latexila.active_doc->path);
GError *error = NULL;
- print_info ("execution of the command: %s", full_command);
+ print_info ("execution of the command: %s", action->command);
- g_spawn_command_line_sync (full_command, &output, NULL, NULL, &error);
+ g_spawn_command_line_sync (action->command, &(action->command_output), NULL, NULL, &error);
g_chdir (dir_backup);
// an error occured
if (error != NULL)
{
- print_warning ("execution failed: %s", error->message);
+ action->command_output = g_strdup_printf (_("execution failed: %s"),
+ error->message);
g_error_free (error);
}
- // show the message of the command
- else
- gtk_text_buffer_set_text (log_buffer, output, -1);
+ print_log (action);
g_free (dir_backup);
g_free (dir);
- g_free (full_command);
- g_free (output);
}
}
static void
-view_document (gchar *doc_type, gchar *doc_extension)
+view_document (action_t *action, gchar *doc_extension)
{
- if (docs.active != NULL)
+ if (latexila.active_doc != NULL)
{
- GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (docs.log);
-
GError *error = NULL;
GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
+ // replace .tex by .pdf
+ gchar *doc_path = g_regex_replace_literal (regex, latexila.active_doc->path,
+ -1, 0, doc_extension, 0, NULL);
+
+ action->command = g_strdup_printf ("evince %s", doc_path);
+
// the current document is a *.tex file?
- gboolean tex_file = g_regex_match (regex, docs.active->path, 0, NULL);
+ gboolean tex_file = g_regex_match (regex, latexila.active_doc->path, 0, NULL);
if (! tex_file)
{
- gchar *text = g_strdup_printf (_("view %s failed: %s is not a *.tex file"),
- doc_type, g_path_get_basename (docs.active->path));
+ action->command_output = g_strdup_printf (_("failed: %s is not a *.tex file"),
+ g_path_get_basename (latexila.active_doc->path));
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
+ print_log (action);
g_regex_unref (regex);
return;
}
- // replace .tex by .pdf
- gchar *doc_path = g_regex_replace_literal (regex, docs.active->path,
- -1, 0, doc_extension, 0, NULL);
-
// the document (PDF, DVI, ...) file exist?
if (! g_file_test (doc_path, G_FILE_TEST_IS_REGULAR))
{
- gchar *text = g_strdup_printf (
+ action->command_output = g_strdup_printf (
_("%s does not exist. If this is not already made, compile the
document with the right command."),
g_path_get_basename (doc_path));
-
- gtk_text_buffer_set_text (log_buffer, text, -1);
- g_free (text);
+
+ print_log (action);
g_free (doc_path);
g_regex_unref (regex);
return;
}
// run the command
- gchar *command = g_strdup_printf ("evince %s", doc_path);
- print_info ("execution of the command: %s", command);
- g_spawn_command_line_async (command, &error);
+ print_info ("execution of the command: %s", action->command);
+ g_spawn_command_line_async (action->command, &error);
if (error != NULL)
{
- print_warning ("execution failed: %s", error->message);
+ action->command_output = g_strdup_printf (_("execution failed: %s"),
+ error->message);
g_error_free (error);
}
+ else
+ action->command_output = g_strdup ("OK");
+
+ print_log (action);
g_regex_unref (regex);
g_free (doc_path);
- g_free (command);
+ }
+}
+
+void
+free_actions (void)
+{
+ while (latexila.active_action != NULL)
+ {
+ action_t *action = latexila.active_action;
+ latexila.all_actions = g_list_remove (latexila.all_actions, action);
+
+ if (action->title != NULL)
+ g_free (action->title);
+ if (action->command != NULL)
+ g_free (action->command);
+ if (action->command_output != NULL)
+ g_free (action->command_output);
+ g_free (action);
+
+ latexila.active_action = g_list_nth_data (latexila.all_actions, 0);
}
}
diff --git a/src/main.c b/src/main.c
index 238c598..2eb66d7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,9 +9,9 @@
#include "main.h"
#include "callbacks.h"
-#include "error.h"
+#include "print.h"
-docs_t docs = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+latexila_t latexila = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
int
main (int argc, char *argv[])
@@ -31,7 +31,7 @@ main (int argc, char *argv[])
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
- docs.main_window = GTK_WINDOW (window);
+ latexila.main_window = GTK_WINDOW (window);
/* boxes */
GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);
@@ -122,12 +122,13 @@ main (int argc, char *argv[])
gtk_ui_manager_get_accel_group (ui_manager));
// get actions
- docs.undo = gtk_ui_manager_get_action (ui_manager, "/MainMenu/Edit/Undo");
- docs.redo = gtk_ui_manager_get_action (ui_manager, "/MainMenu/Edit/Redo");
+ latexila.undo = gtk_ui_manager_get_action (ui_manager, "/MainMenu/Edit/Undo");
+ latexila.redo = gtk_ui_manager_get_action (ui_manager, "/MainMenu/Edit/Redo");
/* vertical pane for the source view and the log zone */
GtkWidget *vpaned = gtk_vpaned_new ();
+ gtk_paned_set_position (GTK_PANED (vpaned), 380);
gtk_box_pack_start (GTK_BOX (main_vbox), vpaned, TRUE, TRUE, 0);
/* source view with tabs */
@@ -135,12 +136,33 @@ main (int argc, char *argv[])
g_signal_connect (G_OBJECT (notebook), "switch-page",
G_CALLBACK (cb_page_change), NULL);
gtk_paned_pack1 (GTK_PANED (vpaned), notebook, TRUE, TRUE);
- docs.notebook = GTK_NOTEBOOK (notebook);
-
- docs.lm = gtk_source_language_manager_get_default ();
+ latexila.notebook = GTK_NOTEBOOK (notebook);
/* log zone */
- //TODO set a default height
+ //TODO set default height and width
+ GtkWidget *hpaned = gtk_hpaned_new ();
+ gtk_paned_set_position (GTK_PANED (hpaned), 190);
+ gtk_paned_pack2 (GTK_PANED (vpaned), hpaned, TRUE, TRUE);
+
+ // actions list
+ GtkListStore *list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
+ latexila.list_store = list_store;
+
+ GtkWidget *list_view = gtk_tree_view_new_with_model (
+ GTK_TREE_MODEL (list_store));
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (
+ "Actions", renderer, "text", COLUMN_ACTION_TITLE, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);
+
+ // with a scrollbar
+ GtkWidget *sw1 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw1),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_paned_pack1 (GTK_PANED (hpaned), sw1, TRUE, TRUE);
+ gtk_container_add (GTK_CONTAINER (sw1), list_view);
+
+ // log details
GtkWidget *log_view = gtk_text_view_new ();
GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (
GTK_TEXT_VIEW (log_view));
@@ -148,13 +170,16 @@ main (int argc, char *argv[])
gtk_text_view_set_editable (GTK_TEXT_VIEW(log_view), FALSE);
// with a scrollbar
- GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GtkWidget *sw2 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw2),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_paned_pack2 (GTK_PANED (vpaned), sw, TRUE, TRUE);
- gtk_container_add (GTK_CONTAINER (sw), log_view);
+ gtk_paned_pack2 (GTK_PANED (hpaned), sw2, TRUE, TRUE);
+ gtk_container_add (GTK_CONTAINER (sw2), log_view);
+
+ latexila.log = GTK_TEXT_VIEW (log_view);
- docs.log = GTK_TEXT_VIEW (log_view);
+ // tags
+ gtk_text_buffer_create_tag (log_buffer, "bold", "font", "bold", NULL);
/* statusbar */
GtkWidget *statusbar = gtk_statusbar_new ();
diff --git a/src/main.h b/src/main.h
index c123cc6..cfe8b97 100644
--- a/src/main.h
+++ b/src/main.h
@@ -11,26 +11,42 @@
// each document opened is represented by a document_t structure
typedef struct
{
- gchar *path;
- gboolean saved;
- GtkWidget *source_view;
- GtkSourceBuffer *source_buffer;
- GtkWidget *title;
+ gchar *path;
+ gboolean saved;
+ GtkWidget *source_view;
+ GtkSourceBuffer *source_buffer;
+ GtkWidget *title;
} document_t;
typedef struct
{
- GList *all;
- document_t *active;
- GtkWindow *main_window;
- GtkNotebook *notebook;
- GtkTextView *log;
- GtkSourceLanguageManager *lm;
- GtkAction *undo;
- GtkAction *redo;
-} docs_t;
+ gchar *title;
+ gchar *command;
+ gchar *command_output;
+} action_t;
+
+typedef struct
+{
+ GList *all_docs;
+ document_t *active_doc;
+ GList *all_actions;
+ action_t *active_action;
+ GtkWindow *main_window;
+ GtkNotebook *notebook;
+ GtkListStore *list_store;
+ GtkTextView *log;
+ GtkAction *undo;
+ GtkAction *redo;
+} latexila_t;
// all the documents are accessible by the docs variable
-extern docs_t docs;
+extern latexila_t latexila;
+
+// for the actions list in the log zone
+enum
+{
+ COLUMN_ACTION_TITLE,
+ N_COLUMNS
+};
#endif /* MAIN_H */
diff --git a/src/print.c b/src/print.c
new file mode 100644
index 0000000..39cd205
--- /dev/null
+++ b/src/print.c
@@ -0,0 +1,68 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
+
+#include "main.h"
+
+void
+print_log (action_t *action)
+{
+ /* append an entry to the action list */
+ GtkTreeIter iter;
+ gtk_list_store_append (latexila.list_store, &iter);
+ gtk_list_store_set (latexila.list_store, &iter, COLUMN_ACTION_TITLE,
+ action->title, -1);
+
+ /* show the details */
+ GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (latexila.log);
+ gtk_text_buffer_set_text (log_buffer, "", -1);
+
+ GtkTextIter end;
+
+ // title (in bold)
+ gtk_text_buffer_get_end_iter (log_buffer, &end);
+ gtk_text_buffer_insert_with_tags_by_name (log_buffer, &end,
+ action->title, -1, "bold", NULL);
+
+ // command
+ gtk_text_buffer_get_end_iter (log_buffer, &end);
+ gchar *command = g_strdup_printf ("\n$ %s\n", action->command);
+ gtk_text_buffer_insert (log_buffer, &end, command, -1);
+ g_free (command);
+
+ // command output
+ gtk_text_buffer_get_end_iter (log_buffer, &end);
+ gtk_text_buffer_insert (log_buffer, &end, action->command_output, -1);
+}
+
+void
+print_info (char *format, ...)
+{
+ va_list va;
+ va_start (va, format);
+ vprintf (format, va);
+ printf ("\n");
+}
+
+void
+print_warning (char *format, ...)
+{
+ va_list va;
+ va_start (va, format);
+ fprintf (stderr, "Warning: ");
+ vfprintf (stderr, format, va);
+ fprintf (stderr, "\n");
+}
+
+void
+print_error (char *format, ...)
+{
+ va_list va;
+ va_start (va, format);
+ fprintf (stderr, "Error: ");
+ vfprintf (stderr, format, va);
+ fprintf (stderr, "\n");
+ exit (EXIT_FAILURE);
+}
diff --git a/src/error.h b/src/print.h
similarity index 52%
rename from src/error.h
rename to src/print.h
index b0307f9..26e592b 100644
--- a/src/error.h
+++ b/src/print.h
@@ -1,8 +1,10 @@
-#ifndef ERROR_H
-#define ERROR_H
-
-void print_info (char *, ...);
-void print_warning (char *, ...);
-void print_error (char *, ...);
-
-#endif /* ERROR_H */
+#ifndef PRINT_H
+#define PRINT_H
+
+void print_log (action_t *action);
+
+void print_info (char *, ...);
+void print_warning (char *, ...);
+void print_error (char *, ...);
+
+#endif /* PRINT_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]