[gnome-latex: 62/205] Edit toolbar: bold, italic, typewriter, underline
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 62/205] Edit toolbar: bold, italic, typewriter, underline
- Date: Fri, 14 Dec 2018 10:52:05 +0000 (UTC)
commit 9829acdf715f2a63c845f74718c3c07bcde8b179
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Mon Sep 14 18:46:06 2009 +0200
Edit toolbar: bold, italic, typewriter, underline
TODO | 5 ++-
images/icons/textbf.png | Bin 0 -> 425 bytes
images/icons/textit.png | Bin 0 -> 309 bytes
images/icons/texttt.png | Bin 0 -> 310 bytes
images/icons/underline.png | Bin 0 -> 381 bytes
src/callbacks.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
src/callbacks.h | 6 ++++
src/prefs.c | 3 +-
src/ui.c | 29 +++++++++++++++--
src/ui.xml | 8 +++++
10 files changed, 125 insertions(+), 4 deletions(-)
---
diff --git a/TODO b/TODO
index c8dd811..f91caaa 100644
--- a/TODO
+++ b/TODO
@@ -14,14 +14,17 @@ Wed Sep 9, 2009 to Wed Sep 16, 2009
[x] check memory leaks
[-] new toolbar
+ x bold, italic, typewriter, underline
- structure: part, chapter, section, subsection, subsubsection, paragraph, subparagraph
- font styles
- size of characters
- - bold, italic, typewriter, underline
- center
- lists: itemize, enumerate, description
- various: label, ref, pageref, cite, footnote, index
+[-] open recent
+ - when "save as", add the file to the recent manager
+
[-] symbol tables
- the categories must take the minimum place but the presentation must be nice
* homogeneous icons
diff --git a/images/icons/textbf.png b/images/icons/textbf.png
new file mode 100644
index 0000000..37815ab
Binary files /dev/null and b/images/icons/textbf.png differ
diff --git a/images/icons/textit.png b/images/icons/textit.png
new file mode 100644
index 0000000..c201b85
Binary files /dev/null and b/images/icons/textit.png differ
diff --git a/images/icons/texttt.png b/images/icons/texttt.png
new file mode 100644
index 0000000..2b89b2a
Binary files /dev/null and b/images/icons/texttt.png differ
diff --git a/images/icons/underline.png b/images/icons/underline.png
new file mode 100644
index 0000000..a5553e7
Binary files /dev/null and b/images/icons/underline.png differ
diff --git a/src/callbacks.c b/src/callbacks.c
index 25f845a..0a724f6 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -52,6 +52,7 @@ static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
static void change_font_source_view (void);
static void create_preferences (void);
static void free_latexila (void);
+static void text_buffer_insert (gchar *text_before, gchar *text_after);
static GtkWidget *pref_dialog = NULL;
@@ -859,6 +860,83 @@ cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data)
gtk_widget_hide (latexila.symbols->vbox);
}
+static void
+text_buffer_insert (gchar *text_before, gchar *text_after)
+{
+ if (latexila.active_doc == NULL)
+ return;
+
+ // we do not use the insert and selection_bound marks because the we don't
+ // know the order. With gtk_text_buffer_get_selection_bounds, we are certain
+ // that "start" points to the start of the selection, where we must insert
+ // "text_before".
+
+ GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+ GtkTextIter start, end;
+ gboolean text_selected = gtk_text_buffer_get_selection_bounds (buffer,
+ &start, &end);
+
+ gtk_text_buffer_begin_user_action (buffer);
+
+ // insert around the selected text
+ // move the cursor to the end
+ if (text_selected)
+ {
+ GtkTextMark *mark_end = gtk_text_buffer_create_mark (buffer, NULL,
+ &end, FALSE);
+ gtk_text_buffer_insert (buffer, &start, text_before, -1);
+ gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
+ gtk_text_buffer_insert (buffer, &end, text_after, -1);
+
+ gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
+ gtk_text_buffer_select_range (buffer, &end, &end);
+ }
+
+ // no text is selected
+ // move the cursor between the 2 texts inserted
+ else
+ {
+ gtk_text_buffer_insert_at_cursor (buffer, text_before, -1);
+
+ GtkTextIter between;
+ gtk_text_buffer_get_iter_at_mark (buffer, &between,
+ gtk_text_buffer_get_insert (buffer));
+ GtkTextMark *mark = gtk_text_buffer_create_mark (buffer, NULL,
+ &between, TRUE);
+
+ gtk_text_buffer_insert_at_cursor (buffer, text_after, -1);
+
+ gtk_text_buffer_get_iter_at_mark (buffer, &between, mark);
+ gtk_text_buffer_select_range (buffer, &between, &between);
+ }
+
+ gtk_text_buffer_end_user_action (buffer);
+}
+
+void
+cb_text_bold (void)
+{
+ text_buffer_insert ("\\textbf{", "}");
+}
+
+void
+cb_text_italic (void)
+{
+ text_buffer_insert ("\\textit{", "}");
+}
+
+void
+cb_text_typewriter (void)
+{
+ text_buffer_insert ("\\texttt{", "}");
+}
+
+void
+cb_text_underline (void)
+{
+ text_buffer_insert ("\\underline{", "}");
+}
+
void
open_new_document (const gchar *filename, const gchar *uri)
{
diff --git a/src/callbacks.h b/src/callbacks.h
index c86b99e..12878e2 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -67,6 +67,12 @@ void cb_category_symbols_selected (GtkIconView *icon_view, gpointer user_data);
void cb_symbol_selected (GtkIconView *icon_view, gpointer user_data);
void cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data);
+// edit toolbar
+void cb_text_bold (void);
+void cb_text_italic (void);
+void cb_text_typewriter (void);
+void cb_text_underline (void);
+
void open_new_document (const gchar *filename, const gchar *uri);
#endif /* CALLBACKS_H */
diff --git a/src/prefs.c b/src/prefs.c
index 61ded6a..18fd32b 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -210,7 +210,8 @@ save_preferences (preferences_t *prefs)
gtk_window_get_size (latexila.main_window, &window_width, &window_height);
// If window is maximized, store sizes that are a bit smaller than full
- // screen, else making window non-fullscreen will have no effect.
+ // screen, else making window non-maximized the next time will have no
+ // effect.
// Attention, the left/top widgets must be packed in paned with
// gtk_paned_add1 () and not "gtk_paned_pack1 (paned, widget, TRUE, TRUE)",
// else the positions panes will inexplicably increase...
diff --git a/src/ui.c b/src/ui.c
index d5de6ce..983471e 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -41,7 +41,11 @@ static struct {
{DATA_DIR "/images/icons/view_pdf.png", "view_pdf"},
{DATA_DIR "/images/icons/view_ps.png", "view_ps"},
{DATA_DIR "/images/icons/dvi_to_pdf.png", "dvi_to_pdf"},
- {DATA_DIR "/images/icons/dvi_to_ps.png", "dvi_to_ps"}
+ {DATA_DIR "/images/icons/dvi_to_ps.png", "dvi_to_ps"},
+ {DATA_DIR "/images/icons/textbf.png", "bold"},
+ {DATA_DIR "/images/icons/textit.png", "italic"},
+ {DATA_DIR "/images/icons/texttt.png", "typewriter"},
+ {DATA_DIR "/images/icons/underline.png", "underline"}
};
// all the actions (for the menu and the toolbar)
@@ -115,6 +119,18 @@ static GtkActionEntry entries[] = {
N_("About LaTeXila"), G_CALLBACK (cb_about_dialog)}
};
+// {name, stock_id, label, accelerator, tooltip, callback}
+static GtkActionEntry edit_entries[] = {
+ {"Bold", "bold", N_("Bold - \\textbf{}"), NULL,
+ N_("Bold - \\textbf{}"), G_CALLBACK (cb_text_bold)},
+ {"Italic", "italic", N_("Italic - \\textit{}"), NULL,
+ N_("Italic - \\textit{}"), G_CALLBACK (cb_text_italic)},
+ {"Typewriter", "typewriter", N_("Typewriter - \\texttt{}"), NULL,
+ N_("Typewriter - \\texttt{}"), G_CALLBACK (cb_text_typewriter)},
+ {"Underline", "underline", N_("Underline - \\underline{}"), NULL,
+ N_("Underline - \\underline{}"), G_CALLBACK (cb_text_underline)}
+};
+
// {name, stock_id, label, accelerator, tooltip, callback}
static GtkToggleActionEntry toggle_entries[] = {
{"ViewSymbols", NULL, N_("Symbol tables"), NULL,
@@ -124,6 +140,7 @@ static GtkToggleActionEntry toggle_entries[] = {
static guint n_stock_icons = G_N_ELEMENTS (stock_icons);
static guint nb_entries = G_N_ELEMENTS (entries);
+static guint nb_edit_entries = G_N_ELEMENTS (edit_entries);
static guint nb_toggle_entries = G_N_ELEMENTS (toggle_entries);
static void
@@ -169,6 +186,8 @@ init_ui (GtkWidget *box)
gtk_action_group_set_translation_domain (action_group, LATEXILA_NLS_PACKAGE);
#endif
gtk_action_group_add_actions (action_group, entries, nb_entries, NULL);
+ gtk_action_group_add_actions (action_group, edit_entries, nb_edit_entries,
+ NULL);
gtk_action_group_add_toggle_actions (action_group, toggle_entries,
nb_toggle_entries, NULL);
gtk_action_group_add_action (action_group, recent);
@@ -186,13 +205,19 @@ init_ui (GtkWidget *box)
}
// get and put the menubar and the toolbar to the main vbox
+ // toolbars with icons only
GtkWidget *menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, FALSE, 0);
+
GtkWidget *toolbar = gtk_ui_manager_get_widget (ui_manager, "/MainToolbar");
- // toolbar with icons only
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
gtk_box_pack_start (GTK_BOX (box), toolbar, FALSE, FALSE, 0);
+ GtkWidget *edit_toolbar = gtk_ui_manager_get_widget (ui_manager,
+ "/EditToolbar");
+ gtk_toolbar_set_style (GTK_TOOLBAR (edit_toolbar), GTK_TOOLBAR_ICONS);
+ gtk_box_pack_start (GTK_BOX (box), edit_toolbar, FALSE, FALSE, 0);
+
// accelerators
gtk_window_add_accel_group (latexila.main_window,
gtk_ui_manager_get_accel_group (ui_manager));
diff --git a/src/ui.xml b/src/ui.xml
index 8258e6e..80b157f 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -82,6 +82,7 @@ In the code, GtkUIManager is used to construct them.
<toolbar name="MainToolbar">
<toolitem action="FileNew" />
<toolitem action="FileOpen" />
+ <!-- TODO add FileOpenRecent with only the arrow -->
<toolitem action="FileSave" />
<separator />
<toolitem action="EditUndo" />
@@ -100,4 +101,11 @@ In the code, GtkUIManager is used to construct them.
<toolitem action="compile_pdflatex" />
<toolitem action="viewPDF" />
</toolbar>
+
+ <toolbar name="EditToolbar">
+ <toolitem action="Bold" />
+ <toolitem action="Italic" />
+ <toolitem action="Typewriter" />
+ <toolitem action="Underline" />
+ </toolbar>
</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]