Commit 9d1486d8 authored by Victor Ananjevsky's avatar Victor Ananjevsky

rename --add-action to --row-action and extend it for other row actions (edit and remove)

parent 7c1dcbae
...@@ -653,8 +653,9 @@ Set the \fICMD\fP as a action when selection is changed. \fICMD\fP will be launc ...@@ -653,8 +653,9 @@ Set the \fICMD\fP as a action when selection is changed. \fICMD\fP will be launc
\fICMD\fP may contain a special character `%s' for setting a position for arguments. By default arguments will be concatenated to the end of \fICMD\fP. \fICMD\fP may contain a special character `%s' for setting a position for arguments. By default arguments will be concatenated to the end of \fICMD\fP.
This option doesn't work with \fI--multiple\fP. This option doesn't work with \fI--multiple\fP.
.TP .TP
.B \-\-add-action=\fICMD\fP .B \-\-row-action=\fICMD\fP
Set the \fICMD\fP as a action when new row is added from a context menu. Command launched without any additional arguments. Output of this command sets the new row values. Set the \fICMD\fP as a action when the row is added, modified or removed. First argument for the command is the name of action (\fIadd\fP, \fIedit\fP or \fIdel\fP).
The rest of command line is data from selected row. Output of this command sets the new row values.
.TP .TP
.B \-\-regex-search .B \-\-regex-search
Use regular expressions in search for text fields. Use regular expressions in search for text fields.
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: YAD\n" "Project-Id-Version: YAD\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-23 14:11+0300\n" "POT-Creation-Date: 2019-07-27 13:24+0300\n"
"PO-Revision-Date: 2009-04-30 16:47+0300\n" "PO-Revision-Date: 2009-04-30 16:47+0300\n"
"Last-Translator: Victor Ananjevsky <ananasik@gmail.com>\n" "Last-Translator: Victor Ananjevsky <ananasik@gmail.com>\n"
"Language-Team: \n" "Language-Team: \n"
...@@ -195,19 +195,23 @@ msgstr "Неизвестная команда '%s'\n" ...@@ -195,19 +195,23 @@ msgstr "Неизвестная команда '%s'\n"
msgid "Yad notification" msgid "Yad notification"
msgstr "Диалог уведомлений" msgstr "Диалог уведомлений"
#: ../src/list.c:898 #: ../src/list.c:966
msgid "Add row" msgid "Add row"
msgstr "Добавить строку" msgstr "Добавить строку"
#: ../src/list.c:903 #: ../src/list.c:971
msgid "Delete row" msgid "Delete row"
msgstr "Удалить строку" msgstr "Удалить строку"
#: ../src/list.c:908 #: ../src/list.c:978
msgid "Edit row"
msgstr "Редактировать строку"
#: ../src/list.c:984
msgid "Duplicate row" msgid "Duplicate row"
msgstr "Скопировать строку" msgstr "Скопировать строку"
#: ../src/list.c:1051 #: ../src/list.c:1125
#, c-format #, c-format
msgid "No column titles specified for List dialog.\n" msgid "No column titles specified for List dialog.\n"
msgstr "Не заданы заголовоки колонок для диалога со списком\n" msgstr "Не заданы заголовоки колонок для диалога со списком\n"
...@@ -986,8 +990,8 @@ msgid "Set select action" ...@@ -986,8 +990,8 @@ msgid "Set select action"
msgstr "Действие при выделении строки" msgstr "Действие при выделении строки"
#: ../src/option.c:451 #: ../src/option.c:451
msgid "Set add action" msgid "Set row action"
msgstr "Действие при добавлении строки" msgstr "Действие над строкой"
#: ../src/option.c:453 #: ../src/option.c:453
msgid "Use regex in search" msgid "Use regex in search"
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: YAD\n" "Project-Id-Version: YAD\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-23 14:11+0300\n" "POT-Creation-Date: 2019-07-27 13:24+0300\n"
"PO-Revision-Date: 2009-04-30 16:47+0300\n" "PO-Revision-Date: 2009-04-30 16:47+0300\n"
"Last-Translator: Victor Ananjevsky <ananasik@gmail.com>\n" "Last-Translator: Victor Ananjevsky <ananasik@gmail.com>\n"
"Language-Team: \n" "Language-Team: \n"
...@@ -195,19 +195,23 @@ msgstr "Невідома команда '%s'\n" ...@@ -195,19 +195,23 @@ msgstr "Невідома команда '%s'\n"
msgid "Yad notification" msgid "Yad notification"
msgstr "Діалог повідомлень" msgstr "Діалог повідомлень"
#: ../src/list.c:898 #: ../src/list.c:966
msgid "Add row" msgid "Add row"
msgstr "Додати рядок" msgstr "Додати рядок"
#: ../src/list.c:903 #: ../src/list.c:971
msgid "Delete row" msgid "Delete row"
msgstr "Видалити рядок" msgstr "Видалити рядок"
#: ../src/list.c:908 #: ../src/list.c:978
msgid "Edit row"
msgstr "Редагувати рядок"
#: ../src/list.c:984
msgid "Duplicate row" msgid "Duplicate row"
msgstr "Скопіювати рядок" msgstr "Скопіювати рядок"
#: ../src/list.c:1051 #: ../src/list.c:1125
#, c-format #, c-format
msgid "No column titles specified for List dialog.\n" msgid "No column titles specified for List dialog.\n"
msgstr "Не задані заголовки стовпчиків для діалогу зі списком\n" msgstr "Не задані заголовки стовпчиків для діалогу зі списком\n"
...@@ -991,8 +995,8 @@ msgid "Set select action" ...@@ -991,8 +995,8 @@ msgid "Set select action"
msgstr "Дія при виділенні стрічки" msgstr "Дія при виділенні стрічки"
#: ../src/option.c:451 #: ../src/option.c:451
msgid "Set add action" msgid "Set row action"
msgstr "Дія при додаванні стрічки" msgstr "Дія над стрічкою"
#: ../src/option.c:453 #: ../src/option.c:453
msgid "Use regex in search" msgid "Use regex in search"
......
...@@ -663,6 +663,8 @@ get_data_as_string (GtkTreeIter *iter) ...@@ -663,6 +663,8 @@ get_data_as_string (GtkTreeIter *iter)
return res; return res;
} }
static void edit_row_cb (GtkMenuItem *item, gpointer data);
static void static void
double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data) double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data)
{ {
...@@ -719,6 +721,8 @@ double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column ...@@ -719,6 +721,8 @@ double_click_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column
g_free (cmd); g_free (cmd);
} }
else if (options.common_data.editable && options.list_data.row_action)
edit_row_cb (NULL, NULL);
else else
{ {
if (options.list_data.checkbox) if (options.list_data.checkbox)
...@@ -781,11 +785,12 @@ add_row_cb (GtkMenuItem *item, gpointer data) ...@@ -781,11 +785,12 @@ add_row_cb (GtkMenuItem *item, gpointer data)
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
gchar *cmd;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (list_view)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (list_view));
yad_list_add_row (GTK_LIST_STORE (model), &iter); yad_list_add_row (GTK_LIST_STORE (model), &iter);
if (options.list_data.add_action) if (options.list_data.row_action)
{ {
gchar *out = NULL; gchar *out = NULL;
gint exit; gint exit;
...@@ -796,7 +801,52 @@ add_row_cb (GtkMenuItem *item, gpointer data) ...@@ -796,7 +801,52 @@ add_row_cb (GtkMenuItem *item, gpointer data)
gtk_main_iteration (); gtk_main_iteration ();
/* run command */ /* run command */
g_spawn_command_line_sync (options.list_data.add_action, &out, NULL, &exit, NULL); cmd = g_strdup_printf ("%s add", options.list_data.row_action);
g_spawn_command_line_sync (cmd, &out, NULL, &exit, NULL);
g_free (cmd);
if (exit == 0)
{
guint i;
gchar **lines = g_strsplit (out, "\n", 0);
for (i = 0; i < n_cols; i++)
{
if (lines[i] == NULL)
break;
cell_set_data (&iter, i, lines[i]);
}
g_strfreev (lines);
}
g_free (out);
}
}
static void
edit_row_cb (GtkMenuItem *item, gpointer data)
{
GtkTreeIter iter;
GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view));
if (!gtk_tree_selection_get_selected (sel, NULL, &iter))
return;
if (options.list_data.row_action)
{
gchar *cmd, *args, *out = NULL;
gint exit;
/* hide menu first */
gtk_menu_popdown (GTK_MENU (data));
while (gtk_events_pending ())
gtk_main_iteration ();
/* run command */
args = get_data_as_string (&iter);
cmd = g_strdup_printf ("%s edit %s", options.list_data.row_action, args);
g_free (args);
g_spawn_command_line_sync (cmd, &out, NULL, &exit, NULL);
g_free (cmd);
if (exit == 0) if (exit == 0)
{ {
guint i; guint i;
...@@ -823,7 +873,29 @@ del_row_cb (GtkMenuItem *item, gpointer data) ...@@ -823,7 +873,29 @@ del_row_cb (GtkMenuItem *item, gpointer data)
GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view)); GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view));
if (gtk_tree_selection_get_selected (sel, NULL, &iter)) if (gtk_tree_selection_get_selected (sel, NULL, &iter))
{
if (options.list_data.row_action)
{
gchar *cmd, *args;
gint exit;
/* hide menu first */
gtk_menu_popdown (GTK_MENU (data));
while (gtk_events_pending ())
gtk_main_iteration ();
/* run command */
args = get_data_as_string (&iter);
cmd = g_strdup_printf ("%s del %s", options.list_data.row_action, args);
g_free (args);
g_spawn_command_line_sync (cmd, NULL, NULL, &exit, NULL);
g_free (cmd);
if (exit == 0)
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
}
else
gtk_list_store_remove (GTK_LIST_STORE (model), &iter); gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
}
} }
static void static void
...@@ -901,6 +973,14 @@ popup_menu_cb (GtkWidget *w, GdkEventButton *ev, gpointer data) ...@@ -901,6 +973,14 @@ popup_menu_cb (GtkWidget *w, GdkEventButton *ev, gpointer data)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (del_row_cb), menu); g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (del_row_cb), menu);
if (options.list_data.row_action)
{
item = gtk_menu_item_new_with_label (_("Edit row"));
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (del_row_cb), menu);
}
item = gtk_menu_item_new_with_label (_("Duplicate row")); item = gtk_menu_item_new_with_label (_("Duplicate row"));
gtk_widget_show (item); gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
......
...@@ -447,8 +447,8 @@ static GOptionEntry list_options[] = { ...@@ -447,8 +447,8 @@ static GOptionEntry list_options[] = {
N_("Set double-click action"), N_("CMD") }, N_("Set double-click action"), N_("CMD") },
{ "select-action", 0, 0, G_OPTION_ARG_STRING, &options.list_data.select_action, { "select-action", 0, 0, G_OPTION_ARG_STRING, &options.list_data.select_action,
N_("Set select action"), N_("CMD") }, N_("Set select action"), N_("CMD") },
{ "add-action", 0, 0, G_OPTION_ARG_STRING, &options.list_data.add_action, { "row-action", 0, 0, G_OPTION_ARG_STRING, &options.list_data.row_action,
N_("Set add action"), N_("CMD") }, N_("Set row action"), N_("CMD") },
{ "regex-search", 0, 0, G_OPTION_ARG_NONE, &options.list_data.regex_search, { "regex-search", 0, 0, G_OPTION_ARG_NONE, &options.list_data.regex_search,
N_("Use regex in search"), NULL }, N_("Use regex in search"), NULL },
{ "no-selection", 0, 0, G_OPTION_ARG_NONE, &options.list_data.no_selection, { "no-selection", 0, 0, G_OPTION_ARG_NONE, &options.list_data.no_selection,
...@@ -1614,7 +1614,7 @@ yad_options_init (void) ...@@ -1614,7 +1614,7 @@ yad_options_init (void)
options.list_data.ellipsize_cols = NULL; options.list_data.ellipsize_cols = NULL;
options.list_data.dclick_action = NULL; options.list_data.dclick_action = NULL;
options.list_data.select_action = NULL; options.list_data.select_action = NULL;
options.list_data.add_action = NULL; options.list_data.row_action = NULL;
options.list_data.regex_search = FALSE; options.list_data.regex_search = FALSE;
options.list_data.clickable = TRUE; options.list_data.clickable = TRUE;
options.list_data.no_selection = FALSE; options.list_data.no_selection = FALSE;
......
...@@ -345,7 +345,7 @@ typedef struct { ...@@ -345,7 +345,7 @@ typedef struct {
gchar *ellipsize_cols; gchar *ellipsize_cols;
gchar *dclick_action; gchar *dclick_action;
gchar *select_action; gchar *select_action;
gchar *add_action; gchar *row_action;
gboolean regex_search; gboolean regex_search;
gboolean clickable; gboolean clickable;
gboolean no_selection; gboolean no_selection;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment