Make the tools->terminal setting more flexible.
Previously was hard coded with options to suit xterm. As this is being replaced with different terminal programs some do not accept the same options. The new setting stores the whole command with %c to substitute the script name. Upgrades old settings if a new one does not exist.
This commit is contained in:
parent
eab86bc6ad
commit
3c2dc547cd
@ -2346,7 +2346,8 @@ Tool paths
|
|||||||
``````````
|
``````````
|
||||||
|
|
||||||
Terminal
|
Terminal
|
||||||
The location of your terminal executable.
|
The command to execute a script in a terminal. Occurrences of %c
|
||||||
|
in the command are substituted with the run script name.
|
||||||
|
|
||||||
Browser
|
Browser
|
||||||
The location of your web browser executable.
|
The location of your web browser executable.
|
||||||
|
44
src/build.c
44
src/build.c
@ -998,25 +998,30 @@ static GPid build_run_cmd(GeanyDocument *doc, guint cmdindex)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
gchar *locale_term_cmd = NULL;
|
gchar *locale_term_cmd = NULL;
|
||||||
gchar **term_argv = NULL;
|
gint argv_len, i;
|
||||||
guint term_argv_len, i;
|
|
||||||
gchar **argv = NULL;
|
gchar **argv = NULL;
|
||||||
|
|
||||||
/* get the terminal path */
|
/* get the terminal path */
|
||||||
locale_term_cmd = utils_get_locale_from_utf8(tool_prefs.term_cmd);
|
locale_term_cmd = utils_get_locale_from_utf8(tool_prefs.term_cmd);
|
||||||
/* split the term_cmd, so arguments will work too */
|
/* split the term_cmd, so arguments will work too */
|
||||||
term_argv = g_strsplit(locale_term_cmd, " ", -1);
|
if (!g_shell_parse_argv(locale_term_cmd, &argv_len, &argv, NULL))
|
||||||
term_argv_len = g_strv_length(term_argv);
|
{
|
||||||
|
ui_set_statusbar(TRUE,
|
||||||
|
_("Could not parse terminal command \"%s\" "
|
||||||
|
"(check Terminal tool setting in Preferences)"), tool_prefs.term_cmd);
|
||||||
|
run_info[cmdindex].pid = (GPid) 1;
|
||||||
|
goto free_strings;
|
||||||
|
}
|
||||||
|
|
||||||
/* check that terminal exists (to prevent misleading error messages) */
|
/* check that terminal exists (to prevent misleading error messages) */
|
||||||
if (term_argv[0] != NULL)
|
if (argv[0] != NULL)
|
||||||
{
|
{
|
||||||
gchar *tmp = term_argv[0];
|
gchar *tmp = argv[0];
|
||||||
/* g_find_program_in_path checks whether tmp exists and is executable */
|
/* g_find_program_in_path checks whether tmp exists and is executable */
|
||||||
term_argv[0] = g_find_program_in_path(tmp);
|
argv[0] = g_find_program_in_path(tmp);
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
}
|
}
|
||||||
if (term_argv[0] == NULL)
|
if (argv[0] == NULL)
|
||||||
{
|
{
|
||||||
ui_set_statusbar(TRUE,
|
ui_set_statusbar(TRUE,
|
||||||
_("Could not find terminal \"%s\" "
|
_("Could not find terminal \"%s\" "
|
||||||
@ -1025,28 +1030,10 @@ static GPid build_run_cmd(GeanyDocument *doc, guint cmdindex)
|
|||||||
goto free_strings;
|
goto free_strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
argv = g_new0(gchar *, term_argv_len + 3);
|
for (i = 0; i < argv_len; i++)
|
||||||
for (i = 0; i < term_argv_len; i++)
|
|
||||||
{
|
{
|
||||||
argv[i] = g_strdup(term_argv[i]);
|
utils_str_replace_all(&(argv[i]), "%c", RUN_SCRIPT_CMD);
|
||||||
}
|
}
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
/* command line arguments only for cmd.exe */
|
|
||||||
if (strstr(argv[0], "cmd.exe") != NULL)
|
|
||||||
{
|
|
||||||
argv[term_argv_len] = g_strdup("/Q /C");
|
|
||||||
argv[term_argv_len + 1] = g_strdup(RUN_SCRIPT_CMD);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
argv[term_argv_len] = g_strdup(RUN_SCRIPT_CMD);
|
|
||||||
argv[term_argv_len + 1] = NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
argv[term_argv_len ] = g_strdup("-e");
|
|
||||||
argv[term_argv_len + 1] = g_strconcat("/bin/sh ", RUN_SCRIPT_CMD, NULL);
|
|
||||||
#endif
|
|
||||||
argv[term_argv_len + 2] = NULL;
|
|
||||||
|
|
||||||
if (! g_spawn_async(working_dir, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
if (! g_spawn_async(working_dir, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
||||||
NULL, NULL, &(run_info[cmdindex].pid), &error))
|
NULL, NULL, &(run_info[cmdindex].pid), &error))
|
||||||
@ -1067,7 +1054,6 @@ static GPid build_run_cmd(GeanyDocument *doc, guint cmdindex)
|
|||||||
}
|
}
|
||||||
free_strings:
|
free_strings:
|
||||||
g_strfreev(argv);
|
g_strfreev(argv);
|
||||||
g_strfreev(term_argv);
|
|
||||||
g_free(locale_term_cmd);
|
g_free(locale_term_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +69,9 @@
|
|||||||
#define GEANY_DISK_CHECK_TIMEOUT 30
|
#define GEANY_DISK_CHECK_TIMEOUT 30
|
||||||
#define GEANY_DEFAULT_TOOLS_MAKE "make"
|
#define GEANY_DEFAULT_TOOLS_MAKE "make"
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
#define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe"
|
#define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe /Q /C %c"
|
||||||
#else
|
#else
|
||||||
#define GEANY_DEFAULT_TOOLS_TERMINAL "xterm"
|
#define GEANY_DEFAULT_TOOLS_TERMINAL "xterm -e \"bin/sh %c\""
|
||||||
#endif
|
#endif
|
||||||
#define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
|
#define GEANY_DEFAULT_TOOLS_BROWSER "firefox"
|
||||||
#define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
|
#define GEANY_DEFAULT_TOOLS_PRINTCMD "lpr"
|
||||||
@ -473,7 +473,7 @@ static void save_dialog_prefs(GKeyFile *config)
|
|||||||
g_key_file_set_string(config, PACKAGE, "pref_template_datetime", template_prefs.datetime_format);
|
g_key_file_set_string(config, PACKAGE, "pref_template_datetime", template_prefs.datetime_format);
|
||||||
|
|
||||||
/* tools settings */
|
/* tools settings */
|
||||||
g_key_file_set_string(config, "tools", "term_cmd", tool_prefs.term_cmd ? tool_prefs.term_cmd : "");
|
g_key_file_set_string(config, "tools", "terminal_cmd", tool_prefs.term_cmd ? tool_prefs.term_cmd : "");
|
||||||
g_key_file_set_string(config, "tools", "browser_cmd", tool_prefs.browser_cmd ? tool_prefs.browser_cmd : "");
|
g_key_file_set_string(config, "tools", "browser_cmd", tool_prefs.browser_cmd ? tool_prefs.browser_cmd : "");
|
||||||
g_key_file_set_string(config, "tools", "grep_cmd", tool_prefs.grep_cmd ? tool_prefs.grep_cmd : "");
|
g_key_file_set_string(config, "tools", "grep_cmd", tool_prefs.grep_cmd ? tool_prefs.grep_cmd : "");
|
||||||
g_key_file_set_string(config, PACKAGE, "context_action_cmd", tool_prefs.context_action_cmd);
|
g_key_file_set_string(config, PACKAGE, "context_action_cmd", tool_prefs.context_action_cmd);
|
||||||
@ -693,6 +693,7 @@ static void load_dialog_prefs(GKeyFile *config)
|
|||||||
{
|
{
|
||||||
gchar *tmp_string, *tmp_string2;
|
gchar *tmp_string, *tmp_string2;
|
||||||
const gchar *default_charset = NULL;
|
const gchar *default_charset = NULL;
|
||||||
|
gchar *cmd;
|
||||||
|
|
||||||
/* compatibility with Geany 0.20 */
|
/* compatibility with Geany 0.20 */
|
||||||
if (!g_key_file_has_key(config, PACKAGE, atomic_file_saving_key, NULL))
|
if (!g_key_file_has_key(config, PACKAGE, atomic_file_saving_key, NULL))
|
||||||
@ -882,7 +883,27 @@ static void load_dialog_prefs(GKeyFile *config)
|
|||||||
template_prefs.datetime_format = utils_get_setting_string(config, PACKAGE, "pref_template_datetime", "%d.%m.%Y %H:%M:%S %Z");
|
template_prefs.datetime_format = utils_get_setting_string(config, PACKAGE, "pref_template_datetime", "%d.%m.%Y %H:%M:%S %Z");
|
||||||
|
|
||||||
/* tools */
|
/* tools */
|
||||||
tool_prefs.term_cmd = utils_get_setting_string(config, "tools", "term_cmd", GEANY_DEFAULT_TOOLS_TERMINAL);
|
cmd = utils_get_setting_string(config, "tools", "terminal_cmd", "");
|
||||||
|
if (!NZV(cmd))
|
||||||
|
{
|
||||||
|
cmd = utils_get_setting_string(config, "tools", "term_cmd", "");
|
||||||
|
if (NZV(cmd))
|
||||||
|
{
|
||||||
|
tmp_string = cmd;
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
if (strstr(cmd, "cmd.exe"))
|
||||||
|
cmd = g_strconcat(cmd, " /Q /C %c", NULL);
|
||||||
|
else
|
||||||
|
cmd = g_strconcat(cmd, " %c", NULL);
|
||||||
|
#else
|
||||||
|
cmd = g_strconcat(cmd, " -e \"/bin/sh %c\"", NULL);
|
||||||
|
#endif
|
||||||
|
g_free(tmp_string);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cmd = g_strdup(GEANY_DEFAULT_TOOLS_TERMINAL);
|
||||||
|
}
|
||||||
|
tool_prefs.term_cmd = cmd;
|
||||||
tool_prefs.browser_cmd = utils_get_setting_string(config, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER);
|
tool_prefs.browser_cmd = utils_get_setting_string(config, "tools", "browser_cmd", GEANY_DEFAULT_TOOLS_BROWSER);
|
||||||
tool_prefs.grep_cmd = utils_get_setting_string(config, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP);
|
tool_prefs.grep_cmd = utils_get_setting_string(config, "tools", "grep_cmd", GEANY_DEFAULT_TOOLS_GREP);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user