summarylogtreecommitdiffstats
path: root/uca_num_files.patch
blob: 362591c53c815c39b56009a8c2d9be31de896871 (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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
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-10-16 13:53:35.000000000 -0400
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.c	2021-10-16 16:52:44.000000000 -0400
@@ -69,12 +69,16 @@ struct _ThunarUcaEditor
   GtkWidget   *shortcut_button;
   GtkWidget   *sn_button;
   GtkWidget   *patterns_entry;
+  GtkWidget   *upper_button;
+  GtkWidget   *lower_button;
   GtkWidget   *directories_button;
   GtkWidget   *audio_files_button;
   GtkWidget   *image_files_button;
   GtkWidget   *text_files_button;
   GtkWidget   *video_files_button;
   GtkWidget   *other_files_button;
+  GtkAdjustment *upper_adjustment;
+  GtkAdjustment *lower_adjustment;
 
   gchar           *accel_path;
   GdkModifierType  accel_mods;
@@ -116,6 +120,8 @@ 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, upper_button);
+  gtk_widget_class_bind_template_child (widget_class, ThunarUcaEditor, lower_button);
   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 +576,8 @@ thunar_uca_editor_load (ThunarUcaEditor
   ThunarUcaTypes types;
   gchar         *description;
   gchar         *patterns;
+  gchar         *upper;
+  gchar         *lower;
   gchar         *command;
   gchar         *icon_name;
   gchar         *name;
@@ -585,6 +593,8 @@ thunar_uca_editor_load (ThunarUcaEditor
   /* determine the current values from the model */
   gtk_tree_model_get (GTK_TREE_MODEL (uca_model), iter,
                       THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &description,
+                      THUNAR_UCA_MODEL_COLUMN_UPPER, &upper,
+                      THUNAR_UCA_MODEL_COLUMN_LOWER, &lower,
                       THUNAR_UCA_MODEL_COLUMN_PATTERNS, &patterns,
                       THUNAR_UCA_MODEL_COLUMN_COMMAND, &command,
                       THUNAR_UCA_MODEL_COLUMN_TYPES, &types,
@@ -614,11 +624,15 @@ 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_spin_button_set_value (GTK_SPIN_BUTTON (uca_editor->upper_button), (upper != NULL) ? g_strtod (upper, NULL) : -1.0);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (uca_editor->lower_button), (lower != NULL) ? g_strtod (lower, NULL) : -1.0);
   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 (upper);
+  g_free (lower);
   g_free (patterns);
   g_free (command);
   g_free (icon_name);
@@ -644,12 +658,17 @@ thunar_uca_editor_save (ThunarUcaEditor
                         GtkTreeIter     *iter)
 {
   gchar         *unique_id;
+  gchar         *upper_string;
+  gchar         *lower_string;
   GtkAccelKey    key;
 
   g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
   g_return_if_fail (THUNAR_UCA_IS_MODEL (uca_model));
   g_return_if_fail (iter != NULL);
 
+  upper_string = g_strdup_printf ("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (uca_editor->upper_button)));
+  lower_string = g_strdup_printf ("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (uca_editor->lower_button)));
+
   gtk_tree_model_get (GTK_TREE_MODEL (uca_model), iter,
                       THUNAR_UCA_MODEL_COLUMN_UNIQUE_ID, &unique_id,
                       -1);
@@ -666,6 +685,8 @@ 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)),
+                           upper_string,
+                           lower_string,
                            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-10-16 13:53:35.000000000 -0400
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-editor.ui	2021-10-16 16:58:17.000000000 -0400
@@ -17,6 +17,20 @@
     <child>
       <placeholder/>
     </child>
+    <object class="GtkAdjustment" id="upper_adjustment">
+      <property name="lower">-1</property>
+      <property name="upper">9999</property>
+      <property name="value">-1</property>
+      <property name="step_increment">1</property>
+      <property name="page_increment">1</property>
+    </object>
+    <object class="GtkAdjustment" id="lower_adjustment">
+      <property name="lower">-1</property>
+      <property name="upper">9999</property>
+      <property name="value">-1</property>
+      <property name="step_increment">1</property>
+      <property name="page_increment">1</property>
+    </object>
     <child internal-child="vbox">
       <object class="GtkBox" id="vbox">
         <property name="can_focus">False</property>
@@ -593,6 +607,68 @@
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkLabel" id="label98">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="no">_Upper (max) number of files:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">upper_button</property>
+                    <property name="xalign">0</property>
+                    <accessibility>
+                      <relation type="label-for" target="upper_button"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="upper_button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="adjustment">upper_adjustment</property>
+                    <property name="climb-rate">1.0</property>
+                    <property name="digits">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label99">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="no">_Lower (min) number of files:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">lower_button</property>
+                    <property name="xalign">0</property>
+                    <accessibility>
+                      <relation type="label-for" target="lower_button"/>
+                    </accessibility>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="lower_button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="adjustment">lower_adjustment</property>
+                    <property name="climb-rate">1.0</property>
+                    <property name="digits">0</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">2</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkLabel" id="label17">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
@@ -602,7 +678,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">1</property>
+                    <property name="top_attach">3</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -702,7 +778,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">2</property>
+                    <property name="top_attach">4</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -745,7 +821,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">4</property>
+                    <property name="top_attach">6</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -763,7 +839,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">3</property>
+                    <property name="top_attach">5</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-10-16 13:53:35.000000000 -0400
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.c	2021-10-16 16:52:24.000000000 -0400
@@ -79,6 +79,8 @@ typedef enum
   PARSER_COMMAND,
   PARSER_STARTUP_NOTIFY,
   PARSER_PATTERNS,
+  PARSER_UPPER,
+  PARSER_LOWER,
   PARSER_DESCRIPTION,
   PARSER_DIRECTORIES,
   PARSER_AUDIO_FILES,
@@ -168,6 +170,8 @@ struct _ThunarUcaModelItem
   gchar         *command;
   guint          startup_notify : 1;
   gchar        **patterns;
+  gchar         *upper;
+  gchar         *lower;
   ThunarUcaTypes types;
 
   /* derived attributes */
@@ -189,6 +193,8 @@ typedef struct
   GString        *command;
   GString        *patterns;
   GString        *description;
+  GString        *upper;
+  GString        *lower;
   gboolean        startup_notify;
   gboolean        description_use;
   guint           description_match;
@@ -333,6 +339,12 @@ thunar_uca_model_get_column_type (GtkTre
     case THUNAR_UCA_MODEL_COLUMN_PATTERNS:
       return G_TYPE_STRING;
 
+    case THUNAR_UCA_MODEL_COLUMN_UPPER:
+      return G_TYPE_STRING;
+
+    case THUNAR_UCA_MODEL_COLUMN_LOWER:
+      return G_TYPE_STRING;
+
     case THUNAR_UCA_MODEL_COLUMN_TYPES:
       return G_TYPE_UINT;
 
@@ -442,6 +454,14 @@ thunar_uca_model_get_value (GtkTreeModel
       g_value_take_string (value, str);
       break;
 
+    case THUNAR_UCA_MODEL_COLUMN_UPPER:
+      g_value_set_static_string (value, item->upper);
+      break;
+
+    case THUNAR_UCA_MODEL_COLUMN_LOWER:
+      g_value_set_static_string (value, item->lower);
+      break;
+
     case THUNAR_UCA_MODEL_COLUMN_TYPES:
       g_value_set_uint (value, item->types);
       break;
@@ -574,6 +594,8 @@ 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.upper = g_string_new (NULL);
+  parser.lower = g_string_new (NULL);
   parser.description = g_string_new (NULL);
   parser.startup_notify = FALSE;
   parser.unique_id_generated = FALSE;
@@ -588,6 +610,8 @@ 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.upper, TRUE);
+  g_string_free (parser.lower, TRUE);
   g_string_free (parser.command, TRUE);
   g_string_free (parser.icon_name, TRUE);
   g_string_free (parser.unique_id, TRUE);
@@ -611,6 +635,8 @@ thunar_uca_model_item_reset (ThunarUcaMo
 {
   /* release the previous values... */
   g_strfreev (item->patterns);
+  g_free (item->upper);
+  g_free (item->lower);
   g_free (item->description);
   g_free (item->command);
   g_free (item->name);
@@ -668,6 +694,8 @@ 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->upper, 0);
+          g_string_truncate (parser->lower, 0);
           g_string_truncate (parser->description, 0);
           xfce_stack_push (parser->stack, PARSER_ACTION);
         }
@@ -725,6 +753,16 @@ start_element_handler (GMarkupParseConte
           g_string_truncate (parser->patterns, 0);
           xfce_stack_push (parser->stack, PARSER_PATTERNS);
         }
+      else if (strcmp (element_name, "upper") == 0)
+        {
+          g_string_truncate (parser->upper, 0);
+          xfce_stack_push (parser->stack, PARSER_UPPER);
+        }
+      else if (strcmp (element_name, "lower") == 0)
+        {
+          g_string_truncate (parser->lower, 0);
+          xfce_stack_push (parser->stack, PARSER_LOWER);
+        }
       else if (strcmp (element_name, "description") == 0)
         {
           for (n = 0; attribute_names[n] != NULL; ++n)
@@ -833,6 +871,8 @@ end_element_handler (GMarkupParseContext
                                    parser->command->str,
                                    parser->startup_notify,
                                    parser->patterns->str,
+                                   parser->upper->str,
+                                   parser->lower->str,
                                    parser->types,
                                    0, 0);
 
@@ -869,6 +909,16 @@ end_element_handler (GMarkupParseContext
         goto unknown_element;
       break;
 
+    case PARSER_UPPER:
+      if (strcmp (element_name, "upper") != 0)
+        goto unknown_element;
+      break;
+
+    case PARSER_LOWER:
+      if (strcmp (element_name, "lower") != 0)
+        goto unknown_element;
+      break;
+
     case PARSER_DESCRIPTION:
       if (strcmp (element_name, "description") != 0)
         goto unknown_element;
@@ -959,6 +1009,14 @@ text_handler (GMarkupParseContext *conte
       g_string_append_len (parser->patterns, text, text_len);
       break;
 
+    case PARSER_UPPER:
+      g_string_append_len (parser->upper, text, text_len);
+      break;
+
+    case PARSER_LOWER:
+      g_string_append_len (parser->lower, text, text_len);
+      break;
+
     case PARSER_DESCRIPTION:
       if (parser->description_use)
         g_string_append_len (parser->description, text, text_len);
@@ -1087,6 +1145,7 @@ thunar_uca_model_match (ThunarUcaModel *
   GList              *lp;
   gint                n_files;
   gint                i, m, n;
+  gint                upper, lower;
   gchar              *path_test;
 
   g_return_val_if_fail (THUNAR_UCA_IS_MODEL (uca_model), NULL);
@@ -1131,7 +1190,15 @@ 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 = g_strtod (item->upper, NULL);
+      lower = g_strtod (item->lower, NULL);
+
+      if (upper == -1)
+        upper = n_files;
+      if (lower == -1)
+        lower = n_files;
+
+      if (((!item->multiple_selection) && (n_files > 1)) || (n_files > upper) || (n_files < lower))
         continue;
 
       /* match the specified files */
@@ -1321,6 +1388,8 @@ thunar_uca_model_update (ThunarUcaModel
                          const gchar    *command,
                          gboolean        startup_notify,
                          const gchar    *patterns,
+                         const gchar    *upper,
+                         const gchar    *lower,
                          ThunarUcaTypes  types,
                          guint           accel_key,
                          GdkModifierType accel_mods)
@@ -1344,6 +1413,10 @@ 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 (upper != NULL && *upper != '\0'))
+    item->upper = g_strdup (upper);
+  if (G_LIKELY (lower != NULL && *lower != '\0'))
+    item->lower = g_strdup (lower);
   if (G_LIKELY (description != NULL && *description != '\0'))
     item->description = g_strdup (description);
   item->types = types;
@@ -1452,12 +1525,16 @@ thunar_uca_model_save (ThunarUcaModel *u
                                          "\t<unique-id>%s</unique-id>\n"
                                          "\t<command>%s</command>\n"
                                          "\t<description>%s</description>\n"
+                                         "\t<upper>%s</upper>\n"
+                                         "\t<lower>%s</lower>\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->upper != NULL) ? item->upper : "",
+                                         (item->lower != NULL) ? item->lower : "",
                                          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-10-16 13:53:35.000000000 -0400
+++ thunar-4.16.10/plugins/thunar-uca/thunar-uca-model.h	2021-10-16 16:52:24.000000000 -0400
@@ -44,6 +44,8 @@ typedef enum
   THUNAR_UCA_MODEL_COLUMN_UNIQUE_ID,
   THUNAR_UCA_MODEL_COLUMN_COMMAND,
   THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY,
+  THUNAR_UCA_MODEL_COLUMN_UPPER,
+  THUNAR_UCA_MODEL_COLUMN_LOWER,
   THUNAR_UCA_MODEL_COLUMN_PATTERNS,
   THUNAR_UCA_MODEL_COLUMN_TYPES,
   THUNAR_UCA_MODEL_COLUMN_STOCK_LABEL,
@@ -96,6 +98,8 @@ void            thunar_uca_model_update
                                                  const gchar            *command,
                                                  gboolean                startup_notify,
                                                  const gchar            *patterns,
+                                                 const gchar            *upper,
+                                                 const gchar            *lower,
                                                  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-10-16 13:53:35.000000000 -0400
+++ thunar-4.16.10/plugins/thunar-uca/uca.xml.in	2021-10-16 16:52:24.000000000 -0400
@@ -38,11 +38,25 @@
   <action>
     <icon>utilities-terminal</icon>
     <patterns>*</patterns>
+    <lower>-1</lower>
+    <upper>-1</upper>
     <_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>
+    <lower>0</lower>
+    <upper>1</upper>
+    <_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>