/
297852-grouping-search-term.patch
2625 lines (2457 loc) · 93.8 KB
/
297852-grouping-search-term.patch
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# HG changeset patch
# User Betterbird <betterbird@betterbird.eu>
# Date 1654088661 -7200
# Parent 4272ec558d4ff140202083eafb26688f92448eb7
Bug 297852 - Allow grouping in search term UI.
This also does a general overhaul of searchTerm.js:
- Removal of hideMatchAllItem() and updateRemoveRowButton()
- Removal of over-engineered global gTotalSearchTerms, badly tracking the length of the search term array
- Removal of gLoading, as a consequence of the gTotalSearchTerms removal
- Removal of gSearchRemovedTerms, we saw no use in tracking removed searchterms
- Moved badly conceived treecols for flex values out of the richlistbox, so the child count matches the richlist items
- Fixed clumsiness in removeSearchRow(): Just remove the row at the given index instead of searching for in the DOM
- Adding an empty search term for new rules, user might want to start off with a group instead
- Mitigation of https://bugzilla.mozilla.org/show_bug.cgi?id=1765077 (missing highlight, focus).
Further clean-up: Removed nsIMsgFilter.AddTerm() and renamed nsIMsgFilter.GetTerm().
* * *
Bug 297852 - Allow grouping in search term UI: Switch to console.log() and fix GitHub issue 60.
* * *
Bug 297852 - Make begins/endsGrouping into intergers to cater for multi-level groups to fix GitHub issue 62.
* * *
Bug 297852 - Validity check after edit, GitHub issue 63.
diff --git a/mail/base/content/SearchDialog.js b/mail/base/content/SearchDialog.js
--- a/mail/base/content/SearchDialog.js
+++ b/mail/base/content/SearchDialog.js
@@ -293,17 +293,16 @@ function searchOnUnload() {
// release this early because msgWindow holds a weak reference
msgWindow.rootDocShell = null;
}
function initializeSearchWindowWidgets() {
gFolderPicker = document.getElementById("searchableFolders");
gSearchStopButton = document.getElementById("search-button");
- hideMatchAllItem();
// eslint-disable-next-line no-global-assign
msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
Ci.nsIMsgWindow
);
msgWindow.domWindow = window;
msgWindow.rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_MAIL;
@@ -363,16 +362,26 @@ function onEnterInSearchTerm() {
) {
onSearch();
} else {
onSearchStop();
onSearch();
}
}
+// Called from searchTerm.js to indicate the number of search terms.
+function hasSearchTerms(count) {
+ let acceptButton = document.getElementById("saveAsVFButton");
+ if (count == 0) {
+ acceptButton.setAttribute("disabled", "true");
+ } else {
+ acceptButton.removeAttribute("disabled");
+ }
+}
+
function onSearch() {
let viewWrapper = gFolderDisplay.view;
let searchTerms = getSearchTerms();
viewWrapper.beginViewUpdate();
viewWrapper.search.userTerms = searchTerms.length ? searchTerms : null;
viewWrapper.search.onlineSearch = gSearchOnline;
viewWrapper.searchFolders = getSearchFolders();
diff --git a/mail/components/addrbook/content/abSearchDialog.js b/mail/components/addrbook/content/abSearchDialog.js
--- a/mail/components/addrbook/content/abSearchDialog.js
+++ b/mail/components/addrbook/content/abSearchDialog.js
@@ -109,18 +109,16 @@ function disableCommands() {
function initializeSearchWindowWidgets() {
gSearchStopButton = document.getElementById("search-button");
gPropertiesCmd = document.getElementById("cmd_properties");
gComposeCmd = document.getElementById("cmd_compose");
gDeleteCmd = document.getElementById("cmd_deleteCard");
gStatusText = document.getElementById("statusText");
disableCommands();
- // matchAll doesn't make sense for address book search
- hideMatchAllItem();
}
function onSearchStop() {}
function onAbSearchReset(event) {
disableCommands();
CloseAbView();
@@ -172,16 +170,20 @@ function onEnterInSearchTerm() {
) {
onSearch();
} else {
onSearchStop();
onSearch();
}
}
+// Called from searchTerm.js to indicate the number of search terms.
+function hasSearchTerms(count) {
+}
+
function onSearch() {
gStatusText.setAttribute("value", "");
disableCommands();
gSearchSession.clearScopes();
var currentAbURI = document.getElementById("abPopup").getAttribute("value");
diff --git a/mail/extensions/mailviews/content/mailViewSetup.js b/mail/extensions/mailviews/content/mailViewSetup.js
--- a/mail/extensions/mailviews/content/mailViewSetup.js
+++ b/mail/extensions/mailviews/content/mailViewSetup.js
@@ -2,16 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from ../../../../mailnews/search/content/searchTerm.js */
document.addEventListener("dialogaccept", onOK);
var gMailView = null;
+var gSearchTermCount = 0;
var dialog;
function mailViewOnLoad() {
initializeSearchWidgets();
initializeMailViewOverrides();
dialog = {};
@@ -80,29 +81,44 @@ function onOK() {
}
function initializeMailViewOverrides() {
// replace some text with something we want. Need to add some ids to searchOverlay.js
// var orButton = document.getElementById('or');
// orButton.setAttribute('label', 'Any of the following');
// var andButton = document.getElementById('and');
// andButton.setAttribute('label', 'All of the following');
- // matchAll doesn't make sense for views, since views are a single folder
- hideMatchAllItem();
}
function UpdateAfterCustomHeaderChange() {
updateSearchAttributes();
}
function doEnabling() {
- if (dialog.nameField.value) {
+ if (gSearchTermCount > 0 && dialog.nameField.value) {
if (dialog.OKButton.disabled) {
dialog.OKButton.disabled = false;
}
} else if (!dialog.OKButton.disabled) {
dialog.OKButton.disabled = true;
}
}
function onEnterInSearchTerm() {
// no-op for us...
}
+
+// Called from searchTerm.js to indicate the number of search terms.
+function hasSearchTerms(count) {
+ gSearchTermCount = count;
+ // We've see this fail with
+ // JavaScript error: chrome://global/content/elements/dialog.js, line 206:
+ // TypeError: can't access property "accept", this._buttons is undefined
+ // So maybe a timeout helps.
+ setTimeout(() => {
+ let acceptButton = document.querySelector("dialog").getButton("accept");
+ if (count == 0 || !dialog.nameField.value) {
+ acceptButton.setAttribute("disabled", "true");
+ } else {
+ acceptButton.removeAttribute("disabled");
+ }
+ }, 100);
+}
diff --git a/mail/locales/en-US/chrome/messenger/search.properties b/mail/locales/en-US/chrome/messenger/search.properties
--- a/mail/locales/en-US/chrome/messenger/search.properties
+++ b/mail/locales/en-US/chrome/messenger/search.properties
@@ -19,9 +19,10 @@ searchingMessage=Searching…
matchesFound=#1 match found;#1 matches found
noMatchesFound=No matches found
labelForStopButton=Stop
labelForSearchButton=Search
labelForStopButton.accesskey=S
labelForSearchButton.accesskey=S
moreButtonTooltipText=Add a new rule
+groupButtonTooltipText=Add a new group
lessButtonTooltipText=Remove this rule
diff --git a/mail/modules/QuickFilterManager.jsm b/mail/modules/QuickFilterManager.jsm
--- a/mail/modules/QuickFilterManager.jsm
+++ b/mail/modules/QuickFilterManager.jsm
@@ -631,23 +631,23 @@ QuickFilterManager.defineFilter({
term.value = value;
term.op = aFilterValue
? Ci.nsMsgSearchOp.IsInAB
: Ci.nsMsgSearchOp.IsntInAB;
// It's an AND if we're the first book (so the boolean affects the
// group as a whole.)
// It's the negation of whether we're filtering otherwise; demorgans.
term.booleanAnd = firstBook || !aFilterValue;
- term.beginsGrouping = firstBook;
+ term.beginsGrouping = firstBook ? 1 : 0;
aTerms.push(term);
firstBook = false;
}
}
if (term) {
- term.endsGrouping = true;
+ term.endsGrouping = 1;
}
},
});
/**
* It's a tag filter that sorta facets! Stealing gloda's thunder! Woo!
*
* Filter on message tags? Meanings:
@@ -770,32 +770,32 @@ var TagFacetingFilter = {
if (showUntagged) {
// We need to OR with the previous condition.
term.booleanAnd = false;
} else {
// AND for the group. Inside the group we also want AND if the
// mode is set to "All of".
term.booleanAnd = firstIncludeClause || mode === "AND";
}
- term.beginsGrouping = firstIncludeClause;
+ term.beginsGrouping = firstIncludeClause ? 1 : 0;
aTerms.push(term);
firstIncludeClause = false;
lastIncludeTerm = term;
} else {
term.op = Ci.nsMsgSearchOp.DoesntContain;
// you need to not include all of the tags marked excluded.
term.booleanAnd = true;
- term.beginsGrouping = firstExcludeClause;
+ term.beginsGrouping = firstExcludeClause ? 1 : 0;
excludeTerms.push(term);
firstExcludeClause = false;
}
}
}
if (lastIncludeTerm) {
- lastIncludeTerm.endsGrouping = true;
+ lastIncludeTerm.endsGrouping = 1;
}
// if we have any exclude terms:
// - we might need to add a "has a tag" clause if there were no explicit
// inclusions.
// - extend the exclusions list in.
if (excludeTerms.length) {
// (we need to add has a tag)
@@ -806,17 +806,17 @@ var TagFacetingFilter = {
value.str = "";
term.value = value;
term.op = Ci.nsMsgSearchOp.IsntEmpty;
term.booleanAnd = !showUntagged;
aTerms.push(term);
}
// (extend in the exclusions)
- excludeTerms[excludeTerms.length - 1].endsGrouping = true;
+ excludeTerms[excludeTerms.length - 1].endsGrouping = 1;
aTerms.push.apply(aTerms, excludeTerms);
}
}
return null;
},
onSearchStart(aCurState) {
// this becomes aKeywordMap; we want to start with an empty one
@@ -1163,23 +1163,23 @@ var MessageTextFilter = {
term.attrib = tfDef.attrib;
value = term.value;
value.attrib = tfDef.attrib;
value.str = phrase;
term.value = value;
term.op = Ci.nsMsgSearchOp.Contains;
// AND for the group, but OR inside the group
term.booleanAnd = firstClause;
- term.beginsGrouping = firstClause;
+ term.beginsGrouping = firstClause ? 1 : 0;
aTerms.push(term);
firstClause = false;
}
}
if (term) {
- term.endsGrouping = true;
+ term.endsGrouping = 1;
}
}
}
},
getDefaults() {
let states = {};
for (let name in this._defaultStates) {
states[name] = this._defaultStates[name];
diff --git a/mail/modules/SearchSpec.jsm b/mail/modules/SearchSpec.jsm
--- a/mail/modules/SearchSpec.jsm
+++ b/mail/modules/SearchSpec.jsm
@@ -165,27 +165,27 @@ SearchSpec.prototype = {
cloneTerm.customId = term.customId;
cloneTerm.op = term.op;
cloneTerm.booleanAnd = term.booleanAnd;
cloneTerm.matchAll = term.matchAll;
term = cloneTerm;
outTerms.push(term);
}
if (iTerm == 0) {
- term.beginsGrouping = true;
- term.endsGrouping = false;
+ term.beginsGrouping = 1;
+ term.endsGrouping = 0;
term.booleanAnd = true;
} else {
- term.beginsGrouping = false;
- term.endsGrouping = false;
+ term.beginsGrouping = 0;
+ term.endsGrouping = 0;
}
iTerm++;
}
if (term) {
- term.endsGrouping = true;
+ term.endsGrouping = 1;
}
return outTerms;
},
/**
* Normalize the provided list of terms so that all of the 'groups' in it are
* ANDed together. If any OR clauses are detected outside of a group, we
diff --git a/mail/themes/linux/mail/filterDialog.css b/mail/themes/linux/mail/filterDialog.css
--- a/mail/themes/linux/mail/filterDialog.css
+++ b/mail/themes/linux/mail/filterDialog.css
@@ -29,11 +29,11 @@
}
.small-button {
min-width: 3em;
padding: 0;
margin: 2px;
}
-.small-button + .small-button {
- margin-inline: 0 4px;
+.small-button:last-of-type {
+ margin-inline-end: 4px;
}
diff --git a/mail/themes/osx/mail/filterDialog.css b/mail/themes/osx/mail/filterDialog.css
--- a/mail/themes/osx/mail/filterDialog.css
+++ b/mail/themes/osx/mail/filterDialog.css
@@ -39,16 +39,15 @@
.small-button:first-child {
margin-inline-start: 2px;
}
listcell > hbox {
-moz-box-pack: end;
}
-/* No '.filler' here, so add margin to make more room. */
-hbox > .small-button + .small-button {
+.small-button:last-of-type {
margin-inline-end: 2px;
}
#searchTermList > listitem[selected="true"] {
background-color: inherit;
}
diff --git a/mail/themes/shared/mail/filterDialog.css b/mail/themes/shared/mail/filterDialog.css
--- a/mail/themes/shared/mail/filterDialog.css
+++ b/mail/themes/shared/mail/filterDialog.css
@@ -79,12 +79,16 @@ checkbox:not([label]) .checkbox-label-bo
#countBox[filterActive="matches"] {
color: #4e9a06;
}
#countBox[filterActive="nomatches"] {
color: #c00;
}
+#booleanAndGroup {
+ margin-inline-end: 4em;
+}
+
#statusbar {
height: 1.8em;
padding: 2px 4px;
}
diff --git a/mail/themes/windows/mail/filterDialog.css b/mail/themes/windows/mail/filterDialog.css
--- a/mail/themes/windows/mail/filterDialog.css
+++ b/mail/themes/windows/mail/filterDialog.css
@@ -32,11 +32,11 @@
padding-block: 3px;
}
.small-button {
min-width: 3em;
margin: 1px 2px;
}
-.small-button + .small-button {
- margin-inline: 0 4px;
+.small-button:last-of-type {
+ margin-inline-end: 4px;
}
diff --git a/mailnews/base/content/virtualFolderProperties.js b/mailnews/base/content/virtualFolderProperties.js
--- a/mailnews/base/content/virtualFolderProperties.js
+++ b/mailnews/base/content/virtualFolderProperties.js
@@ -370,16 +370,32 @@ function updateFoldersCount() {
}
}
function onEnterInSearchTerm() {
// stub function called by the core search widget code...
// nothing for us to do here
}
+// Called from searchTerm.js to indicate the number of search terms.
+function hasSearchTerms(count) {
+ // We've see this fail with
+ // JavaScript error: chrome://global/content/elements/dialog.js, line 206:
+ // TypeError: can't access property "accept", this._buttons is undefined
+ // So maybe a timeout helps.
+ setTimeout(() => {
+ let acceptButton = document.querySelector("dialog").getButton("accept");
+ if (count == 0) {
+ acceptButton.setAttribute("disabled", "true");
+ } else {
+ acceptButton.removeAttribute("disabled");
+ }
+ }, 100);
+}
+
/**
* Clear the tree selection if the user opens the color picker in order to
* guarantee a proper color preview of the highlighted tree item.
*/
function inputColorClicked() {
window.arguments[0].clearFolderSelectionCallback();
gNeedToRestoreFolderSelection = true;
}
diff --git a/mailnews/base/content/virtualFolderProperties.xhtml b/mailnews/base/content/virtualFolderProperties.xhtml
--- a/mailnews/base/content/virtualFolderProperties.xhtml
+++ b/mailnews/base/content/virtualFolderProperties.xhtml
@@ -106,15 +106,18 @@
</hbox>
<separator class="thin"/>
<vbox flex="2">
<label value="&searchTermCaption.label;"/>
<hbox flex="1">
<vbox id="virtualFolderSearchTermListBox" flex="2">
+ <checkbox id="matchAllItem" label="&matchAllMsgs.label;"
+ accesskey="&matchAllMsgs.accesskey;"
+ oncommand="matchAllChanged(event);"/>
#include ../../search/content/searchTerm.inc.xhtml
</hbox>
</vbox>
</dialog>
<script src="chrome://messenger/content/virtualFolderProperties.js"></script>
</html:body>
</html>
diff --git a/mailnews/base/src/MsgIncomingServer.jsm b/mailnews/base/src/MsgIncomingServer.jsm
--- a/mailnews/base/src/MsgIncomingServer.jsm
+++ b/mailnews/base/src/MsgIncomingServer.jsm
@@ -989,18 +989,18 @@ class MsgIncomingServer {
);
filter = serverFilterList.getFilterNamed(yesFilterName);
if (filter && serverFilterTrustFlags & Ci.nsISpamSettings.TRUST_POSITIVES) {
filter.temporary = true;
// Check if we're supposed to move junk mail to junk folder; if so, add
// filter action to do so.
let searchTerms = filter.searchTerms;
if (searchTerms.length) {
- searchTerms[0].beginsGrouping = true;
- searchTerms.at(-1).endsGrouping = true;
+ searchTerms[0].beginsGrouping = 1;
+ searchTerms.at(-1).endsGrouping = 1;
}
// Create a new term, checking if the user set junk status. The term will
// search for junkscoreorigin != "user".
let term = filter.createTerm();
term.attrib = Ci.nsMsgSearchAttrib.JunkScoreOrigin;
term.op = Ci.nsMsgSearchOp.Isnt;
term.booleanAnd = true;
diff --git a/mailnews/base/src/VirtualFolderWrapper.jsm b/mailnews/base/src/VirtualFolderWrapper.jsm
--- a/mailnews/base/src/VirtualFolderWrapper.jsm
+++ b/mailnews/base/src/VirtualFolderWrapper.jsm
@@ -185,18 +185,32 @@ VirtualFolderWrapper.prototype = {
for (let term of aTerms) {
if (condition) {
condition += " ";
}
if (term.matchAll) {
condition = "ALL";
break;
}
- condition += term.booleanAnd ? "AND (" : "OR (";
- condition += term.termAsString + ")";
+ condition += term.booleanAnd ? "AND " : "OR ";
+ if (term.beginsGrouping == 0) {
+ condition += "(";
+ } else {
+ for (let i = 0; i < term.beginsGrouping; i++) {
+ condition += "[";
+ }
+ }
+ condition += term.termAsString;
+ if (term.endsGrouping == 0) {
+ condition += ")";
+ } else {
+ for (let i = 0; i < term.endsGrouping; i++) {
+ condition += "]";
+ }
+ }
}
this.searchString = condition;
},
/**
* @return the set of search terms that define this virtual folder as a
* string. You may prefer to use |searchTerms| which converts them
* into a list of nsIMsgSearchTerms instead.
diff --git a/mailnews/base/src/nsMsgIncomingServer.cpp b/mailnews/base/src/nsMsgIncomingServer.cpp
--- a/mailnews/base/src/nsMsgIncomingServer.cpp
+++ b/mailnews/base/src/nsMsgIncomingServer.cpp
@@ -1724,18 +1724,18 @@ nsresult nsMsgIncomingServer::ConfigureT
// get the list of search terms from the filter
nsTArray<RefPtr<nsIMsgSearchTerm>> searchTerms;
rv = newFilter->GetSearchTerms(searchTerms);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count = searchTerms.Length();
if (count > 1) // don't need to group a single term
{
// beginGrouping the first term, and endGrouping the last term
- searchTerms[0]->SetBeginsGrouping(true);
- searchTerms[count - 1]->SetEndsGrouping(true);
+ searchTerms[0]->SetBeginsGrouping(1);
+ searchTerms[count - 1]->SetEndsGrouping(1);
}
// Create a new term, checking if the user set junk status. The term will
// search for junkscoreorigin != "user"
nsCOMPtr<nsIMsgSearchTerm> searchTerm;
rv = newFilter->CreateTerm(getter_AddRefs(searchTerm));
NS_ENSURE_SUCCESS(rv, rv);
diff --git a/mailnews/base/src/nsMsgUtils.cpp b/mailnews/base/src/nsMsgUtils.cpp
--- a/mailnews/base/src/nsMsgUtils.cpp
+++ b/mailnews/base/src/nsMsgUtils.cpp
@@ -1598,31 +1598,56 @@ MsgTermListToString(nsTArray<RefPtr<nsIM
nsresult rv = NS_OK;
for (nsIMsgSearchTerm* term : aTermList) {
nsAutoCString stream;
if (aOutString.Length() > 1) aOutString += ' ';
bool booleanAnd;
bool matchAll;
+ uint32_t beginsGrouping;
+ uint32_t endsGrouping;
term->GetBooleanAnd(&booleanAnd);
term->GetMatchAll(&matchAll);
+ term->GetBeginsGrouping(&beginsGrouping);
+ term->GetEndsGrouping(&endsGrouping);
if (matchAll) {
aOutString += "ALL";
continue;
- } else if (booleanAnd)
- aOutString += "AND (";
- else
- aOutString += "OR (";
+ } else if (booleanAnd) {
+ if (beginsGrouping == 0) {
+ aOutString += "AND (";
+ } else {
+ aOutString += "AND " ;
+ for (uint32_t i = 0; i < beginsGrouping; i++) {
+ aOutString += "[" ;
+ }
+ }
+ } else {
+ if (beginsGrouping == 0) {
+ aOutString += "OR (";
+ } else {
+ aOutString += "OR " ;
+ for (uint32_t i = 0; i < beginsGrouping; i++) {
+ aOutString += "[" ;
+ }
+ }
+ }
rv = term->GetTermAsString(stream);
NS_ENSURE_SUCCESS(rv, rv);
aOutString += stream;
- aOutString += ')';
+ if (endsGrouping == 0) {
+ aOutString += ")";
+ } else {
+ for (uint32_t i = 0; i < endsGrouping; i++) {
+ aOutString += "]" ;
+ }
+ }
}
return rv;
}
NS_MSG_BASE uint64_t ParseUint64Str(const char* str) {
#ifdef XP_WIN
{
char* endPtr;
diff --git a/mailnews/db/gloda/modules/IndexMsg.jsm b/mailnews/db/gloda/modules/IndexMsg.jsm
--- a/mailnews/db/gloda/modules/IndexMsg.jsm
+++ b/mailnews/db/gloda/modules/IndexMsg.jsm
@@ -758,17 +758,17 @@ var GlodaMsgIndexer = {
this._indexingFolder
);
let nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
let nsMsgSearchOp = Ci.nsMsgSearchOp;
// first term: (GLODA_MESSAGE_ID_PROPERTY Is 0
let searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = false; // actually don't care here
- searchTerm.beginsGrouping = true;
+ searchTerm.beginsGrouping = 1;
searchTerm.attrib = nsMsgSearchAttrib.Uint32HdrProperty;
searchTerm.op = nsMsgSearchOp.Is;
let value = searchTerm.value;
value.attrib = searchTerm.attrib;
value.status = 0;
searchTerm.value = value;
searchTerm.hdrProperty = GLODA_MESSAGE_ID_PROPERTY;
searchTerms.push(searchTerm);
@@ -783,17 +783,17 @@ var GlodaMsgIndexer = {
value.status = GLODA_OLD_BAD_MESSAGE_ID;
searchTerm.value = value;
searchTerm.hdrProperty = GLODA_MESSAGE_ID_PROPERTY;
searchTerms.push(searchTerm);
// third term: || GLODA_DIRTY_PROPERTY Isnt 0 )
searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = false;
- searchTerm.endsGrouping = true;
+ searchTerm.endsGrouping = 1;
searchTerm.attrib = nsMsgSearchAttrib.Uint32HdrProperty;
searchTerm.op = nsMsgSearchOp.Isnt;
value = searchTerm.value;
value.attrib = searchTerm.attrib;
value.status = 0;
searchTerm.value = value;
searchTerm.hdrProperty = GLODA_DIRTY_PROPERTY;
searchTerms.push(searchTerm);
@@ -863,33 +863,33 @@ var GlodaMsgIndexer = {
this._indexingFolder
);
let nsMsgSearchAttrib = Ci.nsMsgSearchAttrib;
let nsMsgSearchOp = Ci.nsMsgSearchOp;
// first term: (GLODA_MESSAGE_ID_PROPERTY > GLODA_FIRST_VALID_MESSAGE_ID-1
let searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = false; // actually don't care here
- searchTerm.beginsGrouping = true;
+ searchTerm.beginsGrouping = 1;
searchTerm.attrib = nsMsgSearchAttrib.Uint32HdrProperty;
// use != 0 if we're allow pre-bad ids.
searchTerm.op = aAllowPreBadIds
? nsMsgSearchOp.Isnt
: nsMsgSearchOp.IsGreaterThan;
let value = searchTerm.value;
value.attrib = searchTerm.attrib;
value.status = aAllowPreBadIds ? 0 : GLODA_FIRST_VALID_MESSAGE_ID - 1;
searchTerm.value = value;
searchTerm.hdrProperty = GLODA_MESSAGE_ID_PROPERTY;
searchTerms.push(searchTerm);
// second term: && GLODA_DIRTY_PROPERTY Isnt kMessageFilthy)
searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = true;
- searchTerm.endsGrouping = true;
+ searchTerm.endsGrouping = 1;
searchTerm.attrib = nsMsgSearchAttrib.Uint32HdrProperty;
searchTerm.op = nsMsgSearchOp.Isnt;
value = searchTerm.value;
value.attrib = searchTerm.attrib;
value.status = this.kMessageFilthy;
searchTerm.value = value;
searchTerm.hdrProperty = GLODA_DIRTY_PROPERTY;
searchTerms.push(searchTerm);
diff --git a/mailnews/db/msgdb/test/unit/test_filter_enumerator.js b/mailnews/db/msgdb/test/unit/test_filter_enumerator.js
--- a/mailnews/db/msgdb/test/unit/test_filter_enumerator.js
+++ b/mailnews/db/msgdb/test/unit/test_filter_enumerator.js
@@ -45,17 +45,17 @@ function run_test() {
localAccountUtils.inboxFolder
);
let searchTerm = searchSession.createTerm();
// Create the following search term:
// (folderFlag & Mail && folderFlag != ImapBox) &&
// msg property.gloda-id isEmpty
- searchTerm.beginsGrouping = true;
+ searchTerm.beginsGrouping = 1;
searchTerm.booleanAnd = true;
searchTerm.attrib = Ci.nsMsgSearchAttrib.FolderFlag;
searchTerm.op = Ci.nsMsgSearchOp.Is;
let value = searchTerm.value;
value.status = Ci.nsMsgFolderFlags.Mail;
value.attrib = Ci.nsMsgSearchAttrib.FolderFlag;
searchTerm.value = value;
searchTerms.push(searchTerm);
@@ -63,17 +63,17 @@ function run_test() {
searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = true;
searchTerm.attrib = Ci.nsMsgSearchAttrib.FolderFlag;
searchTerm.op = Ci.nsMsgSearchOp.Isnt;
value = searchTerm.value;
value.status = Ci.nsMsgFolderFlags.ImapBox;
value.attrib = Ci.nsMsgSearchAttrib.FolderFlag;
searchTerm.value = value;
- searchTerm.endsGrouping = true;
+ searchTerm.endsGrouping = 1;
searchTerms.push(searchTerm);
searchTerm = searchSession.createTerm();
searchTerm.booleanAnd = true;
searchTerm.attrib = Ci.nsMsgSearchAttrib.HdrProperty;
searchTerm.hdrProperty = "gloda-id";
searchTerm.op = Ci.nsMsgSearchOp.IsEmpty;
value = searchTerm.value;
diff --git a/mailnews/search/content/FilterEditor.js b/mailnews/search/content/FilterEditor.js
--- a/mailnews/search/content/FilterEditor.js
+++ b/mailnews/search/content/FilterEditor.js
@@ -153,43 +153,43 @@ function filterEditorOnLoad() {
}
// copy the search terms
for (let searchTerm of copiedFilter.searchTerms) {
let newTerm = newFilter.createTerm();
newTerm.attrib = searchTerm.attrib;
newTerm.op = searchTerm.op;
newTerm.booleanAnd = searchTerm.booleanAnd;
+ newTerm.beginsGrouping = searchTerm.beginsGrouping;
+ newTerm.endsGrouping = searchTerm.endsGrouping;
newTerm.value = searchTerm.value;
newFilter.appendTerm(newTerm);
}
newFilter.filterType = copiedFilter.filterType;
gPreFillName = copiedName;
gFilter = newFilter;
initializeDialog(gFilter);
// We reset the filter name, because otherwise the saveFilter()
// function thinks we are editing a filter, and will thus skip the name
// uniqueness check.
gFilter.filterName = "";
- } else {
- // fake the first more button press
- onMore(null);
}
}
}
if (!gFilter) {
// This is a new filter. Set to both Incoming and Manual contexts.
gFilterTypeSelector.setType(
Ci.nsMsgFilterType.Incoming | Ci.nsMsgFilterType.Manual
);
+ hasSearchTerms(0);
}
// in the case of a new filter, we may not have an action row yet.
ensureActionRow();
gFilterType = gFilterTypeSelector.getType();
gFilterNameElement.select();
// This call is required on mac and linux. It has no effect under win32. See bug 94800.
@@ -201,16 +201,32 @@ function onEnterInSearchTerm(event) {
// If accel key (Ctrl on Win/Linux, Cmd on Mac) was held too, accept the dialog.
document.querySelector("dialog").acceptDialog();
} else {
// If only plain Enter was pressed, add a new rule line.
onMore(event);
}
}
+// Called from searchTerm.js to indicate the number of search terms.
+function hasSearchTerms(count) {
+ // We've see this fail with
+ // JavaScript error: chrome://global/content/elements/dialog.js, line 206:
+ // TypeError: can't access property "accept", this._buttons is undefined
+ // So maybe a timeout helps.
+ setTimeout(() => {
+ let acceptButton = document.querySelector("dialog").getButton("accept");
+ if (count == 0) {
+ acceptButton.setAttribute("disabled", "true");
+ } else {
+ acceptButton.removeAttribute("disabled");
+ }
+ }, 100);
+}
+
function onAccept(event) {
try {
if (!saveFilter()) {
event.preventDefault();
return;
}
} catch (e) {
Cu.reportError(e);
diff --git a/mailnews/search/content/FilterEditor.xhtml b/mailnews/search/content/FilterEditor.xhtml
--- a/mailnews/search/content/FilterEditor.xhtml
+++ b/mailnews/search/content/FilterEditor.xhtml
@@ -104,16 +104,19 @@
command="cmd_updateFilterType"/>
<label id="periodLength"/>
</hbox>
</vbox>
</html:fieldset>
</vbox>
<vbox id="searchTermListBox" flex="1">
+ <checkbox id="matchAllItem" label="&matchAllMsgs.label;"
+ accesskey="&matchAllMsgs.accesskey;"
+ oncommand="matchAllChanged(event);"/>
#include searchTerm.inc.xhtml
<splitter id="gray_horizontal_splitter" persist="state" orient="vertical"/>
<vbox flex="1">
<label value="&filterActionDesc.label;"
accesskey="&filterActionDesc.accesskey;"
control="filterActionList"/>
diff --git a/mailnews/search/content/searchTerm.inc.xhtml b/mailnews/search/content/searchTerm.inc.xhtml
--- a/mailnews/search/content/searchTerm.inc.xhtml
+++ b/mailnews/search/content/searchTerm.inc.xhtml
@@ -1,28 +1,30 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
- <radiogroup id="booleanAndGroup" orient="horizontal" value="and"
- oncommand="booleanChanged(event);">
- <radio value="and" label="&matchAll.label;"
- accesskey="&matchAll.accesskey;" flex="1"/>
- <radio value="or" label="&matchAny.label;"
- accesskey="&matchAny.accesskey;" flex="1"/>
- <radio value="matchAll" id="matchAllItem" label="&matchAllMsgs.label;"
- accesskey="&matchAllMsgs.accesskey;" flex="1"/>
- </radiogroup>
<hbox id="searchTermBox" flex="1"
style="min-height:100px; max-height:100vh;">
- <hbox id="searchterms" class="themeable-brighttext"/>
- <richlistbox flex="1" id="searchTermList">
- <treecols hidden="true">
+ <hbox class="themeable-brighttext"/>
+ <treecols id="flexcols" hidden="true">
<treecol flex="&searchTermListAttributesFlexValue;"/>
<treecol flex="&searchTermListOperatorsFlexValue;"/>
<treecol flex="&searchTermListValueFlexValue;"/>
<treecol class="filler"/>
</treecols>
- </richlistbox>
+ <richlistbox flex="1" id="searchTermList">
+ <richlistitem>
+ <radiogroup id="booleanAndGroup" orient="horizontal" value="and"
+ oncommand="booleanChanged(event);" flex="1" level="0">
+ <radio id="andRadio" value="and" label="&matchAll.label;"
+ accesskey="&matchAll.accesskey;" flex="1"/>
+ <radio id="orRadio" value="or" label="&matchAny.label;"
+ accesskey="&matchAny.accesskey;" flex="1"/>
+ </radiogroup>
+ <button id="moreButton" class="small-button" label="+" oncommand="onMore(event);"/>
+ <button id="groupButton" class="small-button" label="+( )" oncommand="onGroup(event);"/>
+ </richlistitem>
+ </richlistbox>
</hbox>
</vbox>
diff --git a/mailnews/search/content/searchTerm.js b/mailnews/search/content/searchTerm.js
--- a/mailnews/search/content/searchTerm.js
+++ b/mailnews/search/content/searchTerm.js
@@ -1,31 +1,100 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* import-globals-from ../../../mail/components/addrbook/content/abSearchDialog.js */
+/* global hasSearchTerms */
-var gTotalSearchTerms = 0;
-var gSearchTermList;
+var gSearchTermList; // DOM Element of the list of search terms and group headings.
+
+// Array of search terms.
+// Beware: There are more richlist items in `gSearchTermList` than there are search terms
+// since the group headings are also richlistitems.
+// Use `termIdxFromRichlistIdx()` to get from the richlist to the term.
var gSearchTerms = [];
-var gSearchRemovedTerms = [];
+
var gSearchScope;
var gSearchBooleanRadiogroup;
+var gMatchAll;
var gUniqueSearchTermCounter = 0; // gets bumped every time we add a search term so we can always
// dynamically generate unique IDs for the terms.
// cache these so we don't have to hit the string bundle for them
var gMoreButtonTooltipText;
+var gGroupButtonTooltipText;
var gLessButtonTooltipText;
-var gLoading = true;
+
+var verbose = true;
function searchTermContainer() {}
+function dumpSearchTerms(prefix) {
+ if (!verbose) {
+ return;
+ }
+ for (let i = 0; i < gSearchTerms.length; i++) {
+ let beginsGrouping = gSearchTerms[i].obj.beginsGrouping
+ ? `begin(${gSearchTerms[i].obj.beginsGrouping})`
+ : "";
+ let endsGrouping = gSearchTerms[i].obj.endsGrouping
+ ? `end(${gSearchTerms[i].obj.endsGrouping})`
+ : "";
+
+ console.log(
+ `searchTerm: ${prefix} ${i}: ${
+ gSearchTerms[i].obj.booleanAnd ? "and" : "or"
+ } ${beginsGrouping} ${endsGrouping} level ${gSearchTerms[i].level}`
+ );
+ }
+}
+
+function termIdxFromRichlistIdx(index) {
+ if (
+ gSearchTermList.getItemAtIndex(index).firstChild.localName == "radiogroup"
+ ) {
+ // The richlist item doesn't correspond to a term.
+ if (verbose) {
+ console.log(`searchTerm: termIdxFromRichlistIdx ${index} -> -1`);
+ }
+ return -1;
+ }
+ let termIdx = index;
+ for (let i = index; i >= 0; i--) {
+ let item = gSearchTermList.getItemAtIndex(i);
+ if (item.firstChild.localName == "radiogroup") {
+ termIdx--;
+ }
+ }
+ if (verbose) {
+ console.log(`searchTerm: termIdxFromRichlistIdx ${index} -> ${termIdx}`);
+ }
+ return termIdx;
+}
+
+function getLevel(index) {
+ let level;
+ let richlistIdx = index - 1;
+ let itemChild = gSearchTermList.getItemAtIndex(richlistIdx).firstChild;
+ if (itemChild.localName == "radiogroup") {
+ // If the user clicked onto a group, the level is the group's plus one.
+ level = itemChild.getAttribute("level");
+ level = parseInt(level) + 1;
+ } else {
+ let termIdx = termIdxFromRichlistIdx(richlistIdx);
+ level = gSearchTerms[termIdx].level;
+ }
+
+ // eslint-disable-next-line curly
+ if (verbose) console.log(`searchTerm: getLevel ${index} -> ${level}`);
+ return level;
+}
+
searchTermContainer.prototype = {
internalSearchTerm: "",