|
From: <pa...@us...> - 2008-07-31 17:34:03
|
Revision: 538
http://osmo-pim.svn.sourceforge.net/osmo-pim/?rev=538&view=rev
Author: pasp
Date: 2008-07-31 17:34:11 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
* Added function to insert horizontal separator at cursor position in notes editor
Modified Paths:
--------------
trunk/src/gui_utils.c
trunk/src/gui_utils.h
trunk/src/notes.c
Modified: trunk/src/gui_utils.c
===================================================================
--- trunk/src/gui_utils.c 2008-07-31 10:34:49 UTC (rev 537)
+++ trunk/src/gui_utils.c 2008-07-31 17:34:11 UTC (rev 538)
@@ -818,5 +818,30 @@
}
/*------------------------------------------------------------------------------*/
+/* routine by Allin Cottrell */
+gint
+gui_get_char_width (PangoFontDescription *pfd, const gchar *s) {
+GtkWidget *w;
+PangoContext *pc;
+PangoLayout *pl;
+gint width;
+
+ w = gtk_label_new(NULL);
+ pc = gtk_widget_get_pango_context(w);
+ pango_context_set_font_description(pc, pfd);
+
+ pl = pango_layout_new(pc);
+ pango_layout_set_text(pl, s, 1);
+ pango_layout_get_pixel_size(pl, &width, NULL);
+
+ g_object_unref(G_OBJECT(pl));
+ g_object_unref(G_OBJECT(pc));
+ gtk_widget_destroy(w);
+
+ return width;
+}
+
+/*------------------------------------------------------------------------------*/
+
Modified: trunk/src/gui_utils.h
===================================================================
--- trunk/src/gui_utils.h 2008-07-31 10:34:49 UTC (rev 537)
+++ trunk/src/gui_utils.h 2008-07-31 17:34:11 UTC (rev 538)
@@ -44,6 +44,8 @@
gchar* gui_text_buffer_get_text_with_tags (GtkTextBuffer *buffer);
void gui_text_buffer_set_text_with_tags (GtkTextBuffer *buffer, const gchar *text);
+gint gui_get_char_width (PangoFontDescription *pfd, const gchar *s);
+
void gui_change_bg_widget_state (GtkWidget *widget, gchar *color_str, GUI *appGUI);
GdkPixbuf* gui_create_color_swatch (gchar *color);
Modified: trunk/src/notes.c
===================================================================
--- trunk/src/notes.c 2008-07-31 10:34:49 UTC (rev 537)
+++ trunk/src/notes.c 2008-07-31 17:34:11 UTC (rev 538)
@@ -333,6 +333,32 @@
/*------------------------------------------------------------------------------*/
+void
+insert_separator_cb (GtkWidget *widget, gpointer data) {
+
+gint chars, i;
+gchar tmpbuf[BUFFER_SIZE];
+
+ GUI *appGUI = (GUI *)data;
+
+ chars = (appGUI->nte->editor_textview)->allocation.width / gui_get_char_width (appGUI->nte->fd_notes_font, "=");
+
+ if (chars > BUFFER_SIZE) {
+ chars = BUFFER_SIZE - 2; /* \n + null */
+ }
+
+ i = 0;
+ tmpbuf[i++] = '\n';
+ while (i < chars) tmpbuf[i++] = '=';
+ tmpbuf[i++] = '\n';
+ tmpbuf[i] = '\0';
+
+ gtk_text_buffer_insert_at_cursor (gtk_text_view_get_buffer (GTK_TEXT_VIEW (appGUI->nte->editor_textview)),
+ tmpbuf, -1);
+}
+
+/*------------------------------------------------------------------------------*/
+
gint
notes_list_dbclick_cb(GtkWidget * widget, GdkEventButton * event, gpointer func_data) {
@@ -737,6 +763,7 @@
" <toolitem name=\"clear\" action=\"clear\" />\n"
" <separator name=\"sep2\" />\n"
" <toolitem name=\"insert_date_time\" action=\"insert_date_time\" />\n"
+" <toolitem name=\"insert_separator\" action=\"insert_separator\" />\n"
" <separator name=\"sep3\" />\n"
" <toolitem name=\"close\" action=\"close\" />\n"
" </toolbar>\n";
@@ -751,6 +778,7 @@
{ "clear", OSMO_STOCK_EDITOR_CLEAR, _("Clear attributes"), NULL, _("Clear attributes"), NULL },
{ "save", OSMO_STOCK_EDITOR_SAVE, _("Save note"), NULL, _("Save note"), NULL },
{ "insert_date_time", OSMO_STOCK_EDITOR_INSERT_DATE_TIME, _("Insert current date and time"), NULL, _("Insert current date and time"), NULL },
+ { "insert_separator", GTK_STOCK_GOTO_BOTTOM, _("Insert separator"), NULL, _("Insert separator"), NULL },
{ "close", OSMO_STOCK_CLOSE, _("Close editor"), NULL, _("Close editor"), NULL },
};
@@ -1069,6 +1097,8 @@
g_signal_connect (G_OBJECT(gtk_ui_manager_get_widget (appGUI->nte->notes_uim_editor_widget, "/toolbar/insert_date_time")),
"clicked", G_CALLBACK(insert_current_date_and_time_cb), appGUI);
+ g_signal_connect (G_OBJECT(gtk_ui_manager_get_widget (appGUI->nte->notes_uim_editor_widget, "/toolbar/insert_separator")),
+ "clicked", G_CALLBACK(insert_separator_cb), appGUI);
g_signal_connect (G_OBJECT (gtk_ui_manager_get_widget (appGUI->nte->notes_uim_editor_widget, "/toolbar/clear")),
"clicked", G_CALLBACK (clear_text_attributes_cb), appGUI);
g_signal_connect (G_OBJECT (gtk_ui_manager_get_widget (appGUI->nte->notes_uim_editor_widget, "/toolbar/close")),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|