summarylogtreecommitdiffstats
path: root/uca_num_files.patch
blob: 5da5c7c29e6e1458d449d8d6e26ca6df72fce083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
diff -rudp thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-editor.c thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.c
--- thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-editor.c	2021-11-22 15:28:58.000000000 +0000
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.c	2021-11-22 16:49:05.000000000 +0000
@@ -69,6 +69,7 @@ struct _ThunarUcaEditor
   GtkWidget   *shortcut_button;
   GtkWidget   *sn_button;
   GtkWidget   *patterns_entry;
+  GtkWidget   *range_entry;
   GtkWidget   *directories_button;
   GtkWidget   *audio_files_button;
   GtkWidget   *image_files_button;
@@ -116,6 +117,7 @@ thunar_uca_editor_class_init (ThunarUcaE
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, shortcut_button);
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, sn_button);
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, patterns_entry);
+  gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, range_entry);
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, directories_button);
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, audio_files_button);
   gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, image_files_button);
@@ -570,6 +572,7 @@ thunar_uca_editor_load (ThunarUcaEditor
   ThunarUcaTypes types;
   gchar         *description;
   gchar         *patterns;
+  gchar         *range;
   gchar         *command;
   gchar         *icon_name;
   gchar         *name;
@@ -586,6 +589,7 @@ thunar_uca_editor_load (ThunarUcaEditor
   gtk_tree_model_get (GTK_TREE_MODEL (uca_model), iter,
                       THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &description,
                       THUNAR_UCA_MODEL_COLUMN_PATTERNS, &patterns,
+                      THUNAR_UCA_MODEL_COLUMN_RANGE, &range,
                       THUNAR_UCA_MODEL_COLUMN_COMMAND, &command,
                       THUNAR_UCA_MODEL_COLUMN_TYPES, &types,
                       THUNAR_UCA_MODEL_COLUMN_ICON_NAME, &icon_name,
@@ -614,11 +618,13 @@ thunar_uca_editor_load (ThunarUcaEditor
   gtk_entry_set_text (GTK_ENTRY (uca_editor->patterns_entry), (patterns != NULL) ? patterns : "");
   gtk_entry_set_text (GTK_ENTRY (uca_editor->command_entry), (command != NULL) ? command : "");
   gtk_entry_set_text (GTK_ENTRY (uca_editor->name_entry), (name != NULL) ? name : "");
+  gtk_entry_set_text (GTK_ENTRY (uca_editor->range_entry), (range != NULL) ? range : "");
   gtk_button_set_label (GTK_BUTTON (uca_editor->shortcut_button), (accel_label != NULL) ? accel_label : _("None"));
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (uca_editor->sn_button), startup_notify);
 
   /* cleanup */
   g_free (description);
+  g_free (range);
   g_free (patterns);
   g_free (command);
   g_free (icon_name);
@@ -666,6 +672,7 @@ thunar_uca_editor_save (ThunarUcaEditor
                            gtk_entry_get_text (GTK_ENTRY (uca_editor->command_entry)),
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (uca_editor->sn_button)),
                            gtk_entry_get_text (GTK_ENTRY (uca_editor->patterns_entry)),
+                           gtk_entry_get_text (GTK_ENTRY (uca_editor->range_entry)),
                            thunar_uca_editor_get_types (uca_editor),
                            uca_editor->accel_key,
                            uca_editor->accel_mods);
diff -rudp thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-editor.ui thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.ui
--- thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-editor.ui	2021-11-22 15:28:58.000000000 +0000
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.ui	2021-11-22 18:08:09.000000000 +0000
@@ -593,6 +593,37 @@
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkLabel" id="label98">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="no">_Range (min-max):</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">range_entry</property>
+                    <property name="xalign">0</property>
+                    <accessibility>
+                      <relation type="label-for" target="range_entry"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="range_entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="tooltip_text" translatable="yes">If the command should operate on say two or three files, enter the numerical range 2-3. If there are no limits, this string should be anything without the - delimiter.</property>
+                    <property name="hexpand">True</property>
+                    <property name="activates_default">True</property>
+                    <property name="text" translatable="yes">*</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkLabel" id="label17">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
@@ -602,7 +633,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">1</property>
+                    <property name="top_attach">2</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -702,7 +733,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">2</property>
+                    <property name="top_attach">3</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -745,7 +776,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">4</property>
+                    <property name="top_attach">5</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -763,7 +794,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">3</property>
+                    <property name="top_attach">4</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
diff -rudp thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-model.c thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.c
--- thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-model.c	2021-11-22 15:28:58.000000000 +0000
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.c	2021-11-22 17:39:34.000000000 +0000
@@ -79,6 +79,7 @@ typedef enum
   PARSER_COMMAND,
   PARSER_STARTUP_NOTIFY,
   PARSER_PATTERNS,
+  PARSER_RANGE,
   PARSER_DESCRIPTION,
   PARSER_DIRECTORIES,
   PARSER_AUDIO_FILES,
@@ -168,6 +169,7 @@ struct _ThunarUcaModelItem
   gchar         *command;
   guint          startup_notify : 1;
   gchar        **patterns;
+  gchar         *range;
   ThunarUcaTypes types;
 
   /* derived attributes */
@@ -189,6 +191,7 @@ typedef struct
   GString        *command;
   GString        *patterns;
   GString        *description;
+  GString        *range;
   gboolean        startup_notify;
   gboolean        description_use;
   guint           description_match;
@@ -333,6 +336,9 @@ thunar_uca_model_get_column_type (GtkTre
     case THUNAR_UCA_MODEL_COLUMN_PATTERNS:
       return G_TYPE_STRING;
 
+    case THUNAR_UCA_MODEL_COLUMN_RANGE:
+      return G_TYPE_STRING;
+
     case THUNAR_UCA_MODEL_COLUMN_TYPES:
       return G_TYPE_UINT;
 
@@ -442,6 +448,10 @@ thunar_uca_model_get_value (GtkTreeModel
       g_value_take_string (value, str);
       break;
 
+    case THUNAR_UCA_MODEL_COLUMN_RANGE:
+      g_value_set_static_string (value, item->range);
+      break;
+
     case THUNAR_UCA_MODEL_COLUMN_TYPES:
       g_value_set_uint (value, item->types);
       break;
@@ -574,6 +584,7 @@ thunar_uca_model_load_from_file (ThunarU
   parser.icon_name = g_string_new (NULL);
   parser.command = g_string_new (NULL);
   parser.patterns = g_string_new (NULL);
+  parser.range = g_string_new (NULL);
   parser.description = g_string_new (NULL);
   parser.startup_notify = FALSE;
   parser.unique_id_generated = FALSE;
@@ -588,6 +599,7 @@ thunar_uca_model_load_from_file (ThunarU
   g_markup_parse_context_free (context);
   g_string_free (parser.description, TRUE);
   g_string_free (parser.patterns, TRUE);
+  g_string_free (parser.range, TRUE);
   g_string_free (parser.command, TRUE);
   g_string_free (parser.icon_name, TRUE);
   g_string_free (parser.unique_id, TRUE);
@@ -611,6 +623,7 @@ thunar_uca_model_item_reset (ThunarUcaMo
 {
   /* release the previous values... */
   g_strfreev (item->patterns);
+  g_free (item->range);
   g_free (item->description);
   g_free (item->command);
   g_free (item->name);
@@ -668,6 +681,7 @@ start_element_handler (GMarkupParseConte
           g_string_truncate (parser->unique_id, 0);
           g_string_truncate (parser->command, 0);
           g_string_truncate (parser->patterns, 0);
+          g_string_truncate (parser->range, 0);
           g_string_truncate (parser->description, 0);
           xfce_stack_push (parser->stack, PARSER_ACTION);
         }
@@ -725,6 +739,11 @@ start_element_handler (GMarkupParseConte
           g_string_truncate (parser->patterns, 0);
           xfce_stack_push (parser->stack, PARSER_PATTERNS);
         }
+      else if (strcmp (element_name, "range") == 0)
+        {
+          g_string_truncate (parser->range, 0);
+          xfce_stack_push (parser->stack, PARSER_RANGE);
+        }
       else if (strcmp (element_name, "description") == 0)
         {
           for (n = 0; attribute_names[n] != NULL; ++n)
@@ -833,6 +852,7 @@ end_element_handler (GMarkupParseContext
                                    parser->command->str,
                                    parser->startup_notify,
                                    parser->patterns->str,
+                                   parser->range->str,
                                    parser->types,
                                    0, 0);
 
@@ -869,6 +889,11 @@ end_element_handler (GMarkupParseContext
         goto unknown_element;
       break;
 
+    case PARSER_RANGE:
+      if (strcmp (element_name, "range") != 0)
+        goto unknown_element;
+      break;
+
     case PARSER_DESCRIPTION:
       if (strcmp (element_name, "description") != 0)
         goto unknown_element;
@@ -959,6 +984,10 @@ text_handler (GMarkupParseContext *conte
       g_string_append_len (parser->patterns, text, text_len);
       break;
 
+    case PARSER_RANGE:
+      g_string_append_len (parser->range, text, text_len);
+      break;
+
     case PARSER_DESCRIPTION:
       if (parser->description_use)
         g_string_append_len (parser->description, text, text_len);
@@ -1087,6 +1116,8 @@ thunar_uca_model_match (ThunarUcaModel *
   GList              *lp;
   gint                n_files;
   gint                i, m, n;
+  gint                upper, lower;
+  gchar             **limits;
   gchar              *path_test;
 
   g_return_val_if_fail (THUNAR_UCA_IS_MODEL (uca_model), NULL);
@@ -1131,7 +1162,20 @@ thunar_uca_model_match (ThunarUcaModel *
     {
       /* check if we can just ignore this item */
       item = (ThunarUcaModelItem *) lp->data;
-      if (!item->multiple_selection && n_files > 1)
+      upper = n_files;
+      lower = n_files;
+      limits = item->range == NULL ? g_strsplit ("*", "-", 2) : g_strsplit (item->range, "-", 2);
+      if (limits[0] != NULL)
+        {
+          if (limits[1] != NULL)
+            {
+              lower = g_strtod (limits[0], NULL);
+              upper = g_strtod (limits[1], NULL);
+            }
+        }
+      g_strfreev(limits);
+
+      if (((!item->multiple_selection) && (n_files > 1)) || (n_files > upper) || (n_files < lower))
         continue;
 
       /* match the specified files */
@@ -1321,6 +1365,7 @@ thunar_uca_model_update (ThunarUcaModel
                          const gchar    *command,
                          gboolean        startup_notify,
                          const gchar    *patterns,
+                         const gchar    *range,
                          ThunarUcaTypes  types,
                          guint           accel_key,
                          GdkModifierType accel_mods)
@@ -1344,6 +1389,8 @@ thunar_uca_model_update (ThunarUcaModel
     item->icon_name = g_strdup (icon);
   if (G_LIKELY (command != NULL && *command != '\0'))
     item->command = g_strdup (command);
+  if (G_LIKELY (range != NULL && *range != '\0'))
+    item->range = g_strdup (range);
   if (G_LIKELY (description != NULL && *description != '\0'))
     item->description = g_strdup (description);
   item->types = types;
@@ -1452,12 +1499,14 @@ thunar_uca_model_save (ThunarUcaModel *u
                                          "\t<unique-id>%s</unique-id>\n"
                                          "\t<command>%s</command>\n"
                                          "\t<description>%s</description>\n"
+                                         "\t<range>%s</range>\n"
                                          "\t<patterns>%s</patterns>\n",
                                          (item->icon_name != NULL) ? item->icon_name : "",
                                          (item->name != NULL) ? item->name : "",
                                          (item->unique_id != NULL) ? item->unique_id : "",
                                          (item->command != NULL) ? item->command : "",
                                          (item->description != NULL) ? item->description : "",
+                                         (item->range != NULL) ? item->range : "",
                                          patterns);
       fprintf (fp, "%s", escaped);
       g_free (patterns);
diff -rudp thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-model.h thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.h
--- thunar-4.16.10.orig/plugins/thunar-uca/thunar-uca-model.h	2021-11-22 15:28:58.000000000 +0000
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.h	2021-11-22 17:13:19.000000000 +0000
@@ -45,6 +45,7 @@ typedef enum
   THUNAR_UCA_MODEL_COLUMN_COMMAND,
   THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY,
   THUNAR_UCA_MODEL_COLUMN_PATTERNS,
+  THUNAR_UCA_MODEL_COLUMN_RANGE,
   THUNAR_UCA_MODEL_COLUMN_TYPES,
   THUNAR_UCA_MODEL_COLUMN_STOCK_LABEL,
   THUNAR_UCA_MODEL_N_COLUMNS,
@@ -96,6 +97,7 @@ void            thunar_uca_model_update
                                                  const gchar            *command,
                                                  gboolean                startup_notify,
                                                  const gchar            *patterns,
+                                                 const gchar            *range,
                                                  ThunarUcaTypes          types,
                                                  guint                   accel_key,
                                                  GdkModifierType         accel_mods);
diff -rudp thunar-4.16.10.orig/plugins/thunar-uca/uca.xml.in thunar-4.16.10/plugins/thunar-uca/uca.xml.in
--- thunar-4.16.10.orig/plugins/thunar-uca/uca.xml.in	2021-11-22 15:28:58.000000000 +0000
+++ thunar-4.16.10/plugins/thunar-uca/uca.xml.in	2021-11-22 17:14:52.000000000 +0000
@@ -38,11 +38,23 @@
   <action>
     <icon>utilities-terminal</icon>
     <patterns>*</patterns>
+    <range>*</range>
     <_name>Open Terminal Here</_name>
     <command>exo-open --working-directory %f --launch TerminalEmulator</command>
     <_description>Example for a custom action</_description>
     <startup-notify/>
     <directories/>
   </action>
+
+  <action>
+    <icon>preferences-desktop-wallpaper</icon>
+    <patterns>*</patterns>
+    <range>0-1</range>
+    <_name>Set as wallpaper</_name>
+    <command>xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path --create -t string -s \"%f\"</command>
+    <_description>Implementing the entire wallpaper plugin with just a bit of XML</_description>
+    <startup-notify/>
+    <directories/>
+  </action>
 
 </actions>