Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 26 Jun 2014 16:36:51 UTC Commit: 0d03fad7bf478b7bd7aeaee04b1d04be96eb8e86 https://github.com/geany/geany/commit/0d03fad7bf478b7bd7aeaee04b1d04be96eb8e...
Log Message: ----------- Move date insert callbacks to the UI code where they belong
Modified Paths: -------------- src/callbacks.c src/callbacks.h src/ui_utils.c
Modified: src/callbacks.c 73 lines changed, 0 insertions(+), 73 deletions(-) =================================================================== @@ -1286,79 +1286,6 @@ G_MODULE_EXPORT void on_comments_fileheader_activate(GtkMenuItem *menuitem, gpoi }
-static void insert_date(GeanyDocument *doc, gint pos, const gchar *date_style) -{ - const gchar *format = NULL; - gchar *time_str; - - g_return_if_fail(doc != NULL); - g_return_if_fail(pos == -1 || pos >= 0); - - if (pos == -1) - pos = sci_get_current_position(doc->editor->sci); - - /* set default value */ - if (utils_str_equal("", ui_prefs.custom_date_format)) - { - g_free(ui_prefs.custom_date_format); - ui_prefs.custom_date_format = g_strdup("%d.%m.%Y"); - } - - if (utils_str_equal(_("dd.mm.yyyy"), date_style)) - format = "%d.%m.%Y"; - else if (utils_str_equal(_("mm.dd.yyyy"), date_style)) - format = "%m.%d.%Y"; - else if (utils_str_equal(_("yyyy/mm/dd"), date_style)) - format = "%Y/%m/%d"; - else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), date_style)) - format = "%d.%m.%Y %H:%M:%S"; - else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), date_style)) - format = "%m.%d.%Y %H:%M:%S"; - else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), date_style)) - format = "%Y/%m/%d %H:%M:%S"; - else if (utils_str_equal(_("_Use Custom Date Format"), date_style)) - format = ui_prefs.custom_date_format; - else - { - gchar *str = dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets.window), - _("Enter here a custom date and time format. " - "You can use any conversion specifiers which can be used with the ANSI C strftime function."), - ui_prefs.custom_date_format); - if (str) - SETPTR(ui_prefs.custom_date_format, str); - return; - } - - time_str = utils_get_date_time(format, NULL); - if (time_str != NULL) - { - sci_start_undo_action(doc->editor->sci); - sci_insert_text(doc->editor->sci, pos, time_str); - sci_goto_pos(doc->editor->sci, pos + strlen(time_str), FALSE); - sci_end_undo_action(doc->editor->sci); - g_free(time_str); - } - else - { - utils_beep(); - ui_set_statusbar(TRUE, - _("Date format string could not be converted (possibly too long).")); - } -} - - -void on_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data) -{ - insert_date(document_get_current(), editor_info.click_pos, user_data); -} - - -void on_menu_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data) -{ - insert_date(document_get_current(), -1, user_data); -} - - G_MODULE_EXPORT void on_file_properties_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current();
Modified: src/callbacks.h 4 lines changed, 0 insertions(+), 4 deletions(-) =================================================================== @@ -104,8 +104,6 @@ void on_toolbutton_compile_clicked(GtkAction *action, gpointer user_data);
G_MODULE_EXPORT void on_line_wrapping1_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data);
-void on_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data); - void on_toolbutton_goto_entry_activate(GtkAction *action, const gchar *text, gpointer user_data);
void on_toolbutton_goto_clicked(GtkAction *action, gpointer user_data); @@ -132,8 +130,6 @@ G_MODULE_EXPORT void on_menu_toggle_line_commentation1_activate(GtkMenuItem *men
G_MODULE_EXPORT void on_next_message1_activate(GtkMenuItem *menuitem, gpointer user_data);
-void on_menu_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data); - G_MODULE_EXPORT void on_project_new1_activate(GtkMenuItem *menuitem, gpointer user_data);
G_MODULE_EXPORT void on_project_open1_activate(GtkMenuItem *menuitem, gpointer user_data);
Modified: src/ui_utils.c 77 lines changed, 75 insertions(+), 2 deletions(-) =================================================================== @@ -679,6 +679,79 @@ void ui_create_insert_menu_items(void) }
+static void insert_date(GeanyDocument *doc, gint pos, const gchar *date_style) +{ + const gchar *format = NULL; + gchar *time_str; + + g_return_if_fail(doc != NULL); + g_return_if_fail(pos == -1 || pos >= 0); + + if (pos == -1) + pos = sci_get_current_position(doc->editor->sci); + + /* set default value */ + if (utils_str_equal("", ui_prefs.custom_date_format)) + { + g_free(ui_prefs.custom_date_format); + ui_prefs.custom_date_format = g_strdup("%d.%m.%Y"); + } + + if (utils_str_equal(_("dd.mm.yyyy"), date_style)) + format = "%d.%m.%Y"; + else if (utils_str_equal(_("mm.dd.yyyy"), date_style)) + format = "%m.%d.%Y"; + else if (utils_str_equal(_("yyyy/mm/dd"), date_style)) + format = "%Y/%m/%d"; + else if (utils_str_equal(_("dd.mm.yyyy hh:mm:ss"), date_style)) + format = "%d.%m.%Y %H:%M:%S"; + else if (utils_str_equal(_("mm.dd.yyyy hh:mm:ss"), date_style)) + format = "%m.%d.%Y %H:%M:%S"; + else if (utils_str_equal(_("yyyy/mm/dd hh:mm:ss"), date_style)) + format = "%Y/%m/%d %H:%M:%S"; + else if (utils_str_equal(_("_Use Custom Date Format"), date_style)) + format = ui_prefs.custom_date_format; + else + { + gchar *str = dialogs_show_input(_("Custom Date Format"), GTK_WINDOW(main_widgets.window), + _("Enter here a custom date and time format. " + "You can use any conversion specifiers which can be used with the ANSI C strftime function."), + ui_prefs.custom_date_format); + if (str) + SETPTR(ui_prefs.custom_date_format, str); + return; + } + + time_str = utils_get_date_time(format, NULL); + if (time_str != NULL) + { + sci_start_undo_action(doc->editor->sci); + sci_insert_text(doc->editor->sci, pos, time_str); + sci_goto_pos(doc->editor->sci, pos + strlen(time_str), FALSE); + sci_end_undo_action(doc->editor->sci); + g_free(time_str); + } + else + { + utils_beep(); + ui_set_statusbar(TRUE, + _("Date format string could not be converted (possibly too long).")); + } +} + + +static void on_popup_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data) +{ + insert_date(document_get_current(), editor_info.click_pos, user_data); +} + + +static void on_menu_insert_date_activate(GtkMenuItem *menuitem, gpointer user_data) +{ + insert_date(document_get_current(), -1, user_data); +} + + static void insert_date_items(GtkMenu *me, GtkMenu *mp, gchar *label) { GtkWidget *item; @@ -691,7 +764,7 @@ static void insert_date_items(GtkMenu *me, GtkMenu *mp, gchar *label) item = gtk_menu_item_new_with_mnemonic(label); gtk_container_add(GTK_CONTAINER(mp), item); gtk_widget_show(item); - g_signal_connect(item, "activate", G_CALLBACK(on_insert_date_activate), label); + g_signal_connect(item, "activate", G_CALLBACK(on_popup_insert_date_activate), label); }
@@ -734,7 +807,7 @@ void ui_create_insert_date_menu_items(void) item = gtk_menu_item_new_with_mnemonic(str); gtk_container_add(GTK_CONTAINER(menu_popup), item); gtk_widget_show(item); - g_signal_connect(item, "activate", G_CALLBACK(on_insert_date_activate), str); + g_signal_connect(item, "activate", G_CALLBACK(on_popup_insert_date_activate), str); ui_hookup_widget(main_widgets.editor_menu, item, "insert_date_custom2");
insert_date_items(menu_edit, menu_popup, _("_Set Custom Date Format"));
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).