Revision: 1454 http://svn.sourceforge.net/geany/?rev=1454&view=rev Author: eht16 Date: 2007-04-15 12:25:22 -0700 (Sun, 15 Apr 2007)
Log Message: ----------- Run print command asynchronously to prevent blocking of the main process (closes #1695786).
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/keyfile.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-04-15 18:09:59 UTC (rev 1453) +++ trunk/ChangeLog 2007-04-15 19:25:22 UTC (rev 1454) @@ -6,6 +6,9 @@ src/main.c, src/prefs.c: Added context actions to run custom commands on current selection or the current word below cursor. + * src/document.c, src/keyfile.c: + Run print command asynchronously to prevent blocking of the main + process (closes #1695786).
2007-04-15 Nick Treleaven nick.treleaven@btinternet.com
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2007-04-15 18:09:59 UTC (rev 1453) +++ trunk/src/document.c 2007-04-15 19:25:22 UTC (rev 1454) @@ -1329,7 +1329,7 @@ void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags, gboolean escaped_chars) { - gint selection_end, selection_start, selection_mode, selected_lines, last_line; + gint selection_end, selection_start, selection_mode, selected_lines, last_line = 0; gint max_column = 0, count = 0; gboolean replaced = FALSE;
@@ -1735,7 +1735,8 @@ { gchar *cmdline;
- if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_name == NULL) return; + if (! DOC_IDX_VALID(idx) || doc_list[idx].file_name == NULL) + return;
cmdline = g_strdup(app->tools_print_cmd); cmdline = utils_str_replace(cmdline, "%f", doc_list[idx].file_name); @@ -1743,19 +1744,29 @@ if (dialogs_show_question(_("The file "%s" will be printed with the following command:\n\n%s"), doc_list[idx].file_name, cmdline)) { - gint rc; - // system() is not the best way, but the only one I found to get the following working: - // a2ps -1 --medium=A4 -o - %f | xfprint4 - rc = system(cmdline); - if (rc != 0) + GError *error = NULL; + +#ifdef G_OS_WIN32 + gchar *tmp_cmdline = cmdline; +#else + // /bin/sh -c emulates the system() call and makes complex commands possible + // but only needed on non-win32 systems due to the lack of win32's shell capabilities + gchar *tmp_cmdline = g_strconcat("/bin/sh -c "", cmdline, """, NULL); +#endif + + if (! g_spawn_command_line_async(tmp_cmdline, &error)) { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of "%s" failed (return code: %d)."), - doc_list[idx].file_name, rc); + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of "%s" failed (return code: %s)."), + doc_list[idx].file_name, error->message); + g_error_free(error); } else { msgwin_status_add(_("File %s printed."), doc_list[idx].file_name); } +#ifndef G_OS_WIN32 + g_free(tmp_cmdline); +#endif } g_free(cmdline); }
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2007-04-15 18:09:59 UTC (rev 1453) +++ trunk/src/keyfile.c 2007-04-15 19:25:22 UTC (rev 1454) @@ -470,7 +470,12 @@ g_free(tmp_string);
tmp_string2 = g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD); +#ifdef G_OS_WIN32 + // single quote paths on Win32 for g_spawn_command_line_async + tmp_string = g_strconcat("'", tmp_string2, "' '%f'", NULL); +#else tmp_string = g_strconcat(tmp_string2, " %f", NULL); +#endif app->tools_print_cmd = utils_get_setting_string(config, "tools", "print_cmd", tmp_string); g_free(tmp_string); g_free(tmp_string2);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.