[gnome-latex: 20/205] tabs with close button
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 20/205] tabs with close button
- Date: Fri, 14 Dec 2018 10:48:33 +0000 (UTC)
commit 5d88733b9ea3f7a0a6918710d11502178af69c59
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Tue Aug 18 14:27:12 2009 +0200
tabs with close button
TODO | 62 ++++++++++++---------
src/callbacks.c | 170 +++++++++++++++++++++++++++++++++++++-------------------
src/callbacks.h | 1 +
src/main.c | 7 +--
src/main.h | 1 +
5 files changed, 155 insertions(+), 86 deletions(-)
---
diff --git a/TODO b/TODO
index c9392e9..902e8f5 100644
--- a/TODO
+++ b/TODO
@@ -1,27 +1,39 @@
TODO LaTeXila
-Jul 31, 2009 to Aug 7, 2009
-
-[x] about dialog
-
-[-] files
- x open
- x save
- x save as
- x new
- x close
- x tabs
- x change title of tabs
- - tabs with close buttons
-
-[x] GtkSourceView
- x syntaxic color
- x show/hide line numbers
- x undo/redo
- x font monospace
-
-[x] compile and view
- x compile (pdflatex)
- x view PDF
- x compile (latex)
- x view DVI
+Tue Aug 18, 2009 to Mon Aug 24, 2009
+
+[x] tabs with close buttons
+
+[-] log zone
+ - horizontal pane
+ left: list with an history of the actions numbered
+ right: details of the action selected
+ - function print_log ()
+ - default height and width
+
+[-] statusbar
+ - function print_statusbar ()
+ - write some text in the statusbar
+ - show which line and which column the cursor is
+
+[-] icons: PDF, DVI, ...
+
+[-] DVI to PDF, DVI to PS
+
+
+Tue Aug 25, 2009 to Mon Aug 31, 2009
+
+[-] files recently opened (in the File menu)
+
+[-] search and replace
+
+[-] CMake
+
+[-] French translation
+
+[-] apply the GPL
+
+[-] GNOME integration
+ - open *.tex file with LaTeXila
+
+[-] ubuntu package
diff --git a/src/callbacks.c b/src/callbacks.c
index a9c916e..6e0a389 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -13,7 +13,8 @@
#include "callbacks.h"
#include "error.h"
-static void create_document_in_new_tab (gchar *path, gchar *text, GtkWidget *label);
+static void create_document_in_new_tab (gchar *path, gchar *text, gchar *title);
+static void close_document (gint index);
static void save_as_dialog (void);
static void file_save (void);
static gboolean close_all (void);
@@ -28,9 +29,8 @@ cb_new (void)
char *default_text = "\\documentclass[a4paper,11pt]{article}\n"
"\\begin{document}\n"
"\\end{document}";
- GtkWidget *label = gtk_label_new (_("New document"));
- create_document_in_new_tab (NULL, default_text, label);
+ create_document_in_new_tab (NULL, default_text, _("New document"));
}
void
@@ -55,8 +55,8 @@ cb_open (void)
// convert the text to UTF-8
gchar *text_utf8 = g_locale_to_utf8 (contents, -1, NULL, NULL, NULL);
- GtkWidget *label = gtk_label_new (g_path_get_basename (filename));
- create_document_in_new_tab (filename, text_utf8, label);
+ create_document_in_new_tab (filename, text_utf8,
+ g_path_get_basename (filename));
g_free (contents);
g_free (text_utf8);
}
@@ -112,52 +112,33 @@ cb_close (void)
{
if (docs.active != NULL)
{
- /* if the document is not saved, ask the user for saving changes before
- * closing */
- if (! docs.active->saved)
- {
- GtkWidget *dialog = gtk_dialog_new_with_buttons (
- _("Close the document"),
- docs.main_window,
- GTK_DIALOG_MODAL,
- GTK_STOCK_YES, GTK_RESPONSE_YES,
- GTK_STOCK_NO, GTK_RESPONSE_NO,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- NULL
- );
- GtkWidget *label = gtk_label_new (_("Save changes to document before closing?"));
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE, FALSE, 10);
- gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+ gint index = gtk_notebook_get_current_page (docs.notebook);
+ close_document (index);
- switch (gtk_dialog_run (GTK_DIALOG (dialog)))
- {
- // save changes before closing
- case GTK_RESPONSE_YES:
- cb_save ();
- break;
+ if (gtk_notebook_get_n_pages (docs.notebook) > 0)
+ docs.active = g_list_nth_data (docs.all, gtk_notebook_get_current_page
(docs.notebook));
+ else
+ docs.active = NULL;
- // close the document without saving changes
- case GTK_RESPONSE_NO:
- break;
-
- // do nothing, the document is not closed
- case GTK_RESPONSE_CANCEL:
- gtk_widget_destroy (dialog);
- return;
- }
+ set_undo_redo_sensitivity ();
+ }
- gtk_widget_destroy (dialog);
- }
+ else
+ print_warning ("no document opened");
+}
+
+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);
+
+ // the document to close is the current document
+ if (docs.active == doc_backup)
+ {
+ close_document (page_to_close);
- /* close the tab */
- docs.all = g_list_remove (docs.all, docs.active);
- if (docs.active->path != NULL)
- {
- print_info ("close the file \"%s\"", docs.active->path);
- g_free (docs.active->path);
- }
- g_free (docs.active);
- gtk_notebook_remove_page (docs.notebook, gtk_notebook_get_current_page (docs.notebook));
if (gtk_notebook_get_n_pages (docs.notebook) > 0)
docs.active = g_list_nth_data (docs.all, gtk_notebook_get_current_page
(docs.notebook));
else
@@ -166,8 +147,12 @@ cb_close (void)
set_undo_redo_sensitivity ();
}
+ // the document to close is not the current document
else
- print_warning ("no document opened");
+ {
+ close_document (page_to_close);
+ docs.active = doc_backup;
+ }
}
void
@@ -302,7 +287,7 @@ cb_page_change (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gp
*****************************/
static void
-create_document_in_new_tab (gchar *path, gchar *text, GtkWidget *label)
+create_document_in_new_tab (gchar *path, gchar *text, gchar *title)
{
// create a new document_t structure
// if path = NULL, this is a new document
@@ -360,12 +345,87 @@ create_document_in_new_tab (gchar *path, gchar *text, GtkWidget *label)
gtk_widget_show_all (sw);
// add the new document in a new tab
- gint index = gtk_notebook_append_page (docs.notebook, sw, label);
- gtk_notebook_set_current_page (docs.notebook, index);
+ // TODO set height
+ GtkWidget *hbox = gtk_hbox_new (FALSE, 3);
+
+ GtkWidget *label = gtk_label_new (title);
+ new_doc->title = label;
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ GtkWidget *close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ GtkWidget *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_tab), sw);
+ 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);
+
set_undo_redo_sensitivity ();
}
+static void
+close_document (gint index)
+{
+ if (docs.active != NULL)
+ {
+ /* if the document is not saved, ask the user for saving changes before
+ * closing */
+ if (! docs.active->saved)
+ {
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (
+ _("Close the document"),
+ docs.main_window,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_YES, GTK_RESPONSE_YES,
+ GTK_STOCK_NO, GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL
+ );
+ GtkWidget *label = gtk_label_new (_("Save changes to document before closing?"));
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, TRUE, FALSE, 10);
+ gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+
+ switch (gtk_dialog_run (GTK_DIALOG (dialog)))
+ {
+ // save changes before closing
+ case GTK_RESPONSE_YES:
+ cb_save ();
+ break;
+
+ // close the document without saving changes
+ case GTK_RESPONSE_NO:
+ break;
+
+ // do nothing, the document is not closed
+ case GTK_RESPONSE_CANCEL:
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ gtk_widget_destroy (dialog);
+ }
+
+ /* close the tab */
+ docs.all = g_list_remove (docs.all, docs.active);
+ if (docs.active->path != NULL)
+ {
+ print_info ("close the file \"%s\"", docs.active->path);
+ g_free (docs.active->path);
+ }
+ g_free (docs.active);
+
+ gtk_notebook_remove_page (docs.notebook, index);
+ }
+
+ else
+ print_warning ("no document opened");
+}
+
static void
save_as_dialog (void)
{
@@ -453,13 +513,9 @@ set_title (void)
else
title = g_strdup_printf ("*%s", tmp);
- g_free (tmp);
-
- gint index = gtk_notebook_get_current_page (docs.notebook);
- GtkWidget *child = gtk_notebook_get_nth_page (docs.notebook, index);
- GtkLabel *label = GTK_LABEL (gtk_notebook_get_tab_label (docs.notebook, child));
- gtk_label_set_text (label, title);
+ gtk_label_set_text (GTK_LABEL (docs.active->title), title);
+ g_free (tmp);
g_free (title);
}
}
diff --git a/src/callbacks.h b/src/callbacks.h
index 4bb5025..521f488 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -6,6 +6,7 @@ void cb_open (void);
void cb_save (void);
void cb_save_as (void);
void cb_close (void);
+void cb_close_tab (GtkWidget *widget, GtkWidget *child);
void cb_quit (void);
void cb_undo (void);
void cb_redo (void);
diff --git a/src/main.c b/src/main.c
index 01b9e4d..238c598 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,8 +43,8 @@ main (int argc, char *argv[])
// name, stock_id, label, accelerator, tooltip, callback
// the names come from the XML file
//
- //TODO try to place "entries" out of the main function without errors
- //because of gettext (the _() macro)
+ // TODO try to place "entries" out of the main function without errors
+ // because of gettext (the _() macro)
GtkActionEntry entries[] =
{
{"File", NULL, _("File"), NULL, NULL, NULL},
@@ -137,8 +137,7 @@ main (int argc, char *argv[])
gtk_paned_pack1 (GTK_PANED (vpaned), notebook, TRUE, TRUE);
docs.notebook = GTK_NOTEBOOK (notebook);
- GtkSourceLanguageManager *lm = gtk_source_language_manager_get_default ();
- docs.lm = lm;
+ docs.lm = gtk_source_language_manager_get_default ();
/* log zone */
//TODO set a default height
diff --git a/src/main.h b/src/main.h
index 418aa57..c123cc6 100644
--- a/src/main.h
+++ b/src/main.h
@@ -15,6 +15,7 @@ typedef struct
gboolean saved;
GtkWidget *source_view;
GtkSourceBuffer *source_buffer;
+ GtkWidget *title;
} document_t;
typedef struct
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]