Closed Bug 1459184 Opened 6 years ago Closed 6 years ago

Port |Bug 1456611 - Remove insertItemAt and removeItemAt methods from XUL widgets|

Categories

(Thunderbird :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 61.0

People

(Reporter: jorgk-bmo, Assigned: aceman)

References

Details

Attachments

(2 files, 4 obsolete files)

Assignee: nobody → acelists
Status: NEW → ASSIGNED
Attached patch 1459184.patch (obsolete) — Splinter Review
I manually tested most of the places, I just didn't test the editor changes and the cloudfile account.

Try run: https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=56f86a10cc336ed49ee2bd06f687bce9b4f2e235
Attachment #8973367 - Flags: review?(jorgk)
Attached patch 1459184-cal.patch (obsolete) — Splinter Review
Replacements in calendar.
Attachment #8973368 - Flags: review?(philipp)
Comment on attachment 8973368 [details] [diff] [review]
1459184-cal.patch

Review of attachment 8973368 [details] [diff] [review]:
-----------------------------------------------------------------

r+wc

::: calendar/base/content/widgets/calendar-widgets.xml
@@ +136,4 @@
>  
>              if (!item || item.getAttribute("value") != category) {
>                  // The item doesn't exist, insert it at the correct spot.
>                  item = categoryListbox.insertItemAt(newIndex, category, category);

The new code still has insertItemAt, maybe you missed removing this?

@@ +141,5 @@
> +                item = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "listitem");
> +                item.setAttribute("label", category);
> +                item.setAttribute("value", category);
> +                let beforeItem = categoryListbox.getItemAtIndex(newIndex);
> +                if (beforeItem)

brackets for if and else here. That aside, I believe calling node.insertBefore(item, null) is the same as calling appendChild. So you could drop the if block entirely. Please test before you do though :)
Attachment #8973368 - Flags: review?(philipp) → review+
The biggest problem is that the Gecko decision task is busted and we can't build anything. Not on try and not elsewhere :-(
Still working at f5a77c38b072, so down to
https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=f5a77c38b072&tochange=5207b1392b11

For some reason the link doesn't work :-( It's these:
f124a57ef00a	Joel Maher — Bug 1455316 - sometimes when test-verify finds a failure, all future tests are marked as failing also. r=gbrown
64703ce328ea	Joel Maher — Bug 1442893 - disable ts_paint_heavy on osx due to length of time to unpack profile. r=rwood
7ba78b394fcb	Cosmin Sabou — Merge mozilla-central to inbound. a=merge CLOSED TREE
4065e9400f2b	Olli Pettay — Bug 1458694 - (android) ensure context menu works with ShadowDOM, r=JanH
f529be04c5a7	Nathan Froyd — Bug 1459035 - micro-optimize refcounting for nsSocket{Input,Output}Stream; r=valentin
92a50917efbc	vidit23 — Bug 1453957 - Stop setting the "unread" attribute on tabs. r=dao
b95fbd8db183	J.C. Jones — Bug 1445731 - land NSS NSS_3_37_RTM UPGRADE_NSS_RELEASE, r=me
af05b5813fc7	Gabriel Luong — Bug 1459257 - Check the inspector is visible before showing the 3 pane onboarding tooltip. r=jdescottes
0eade0cff0d6	Aaron Klotz — Bug 1459085: Prevent mutex reentry in mscom::Interceptor::GetInterceptorForIID; r=Jamie

I've looked through these and the only build related changes are in
64703ce328ea	Joel Maher — Bug 1442893 - disable ts_paint_heavy on osx due to length of time to unpack profile. r=rwood
Confirmed with further tries that bug 1442893 caused the build failure.
So the question is, how to port a one line deletion to TB:
https://hg.mozilla.org/mozilla-central/rev/64703ce328ea
--- a/taskcluster/ci/test/test-sets.yml
-    - talos-h1
+    # - talos-h1 # too long to unpack profile- Bug 1442893

Strangely enough M-C f529be04c5a7 worked and 64703ce328ea and 7ba78b394fcb(??) failed. Strange.
Comment on attachment 8973367 [details] [diff] [review]
1459184.patch

Review of attachment 8973367 [details] [diff] [review]:
-----------------------------------------------------------------

::: mail/base/content/ABSearchDialog.js
@@ -63,5 @@
>    // Initialize globals, see abCommon.js , InitCommonJS()
>    abList = document.getElementById("abPopup");
> -  if (abList.getItemAtIndex(0) != (kAllDirectoryRoot + "?"))
> -    abList.insertItemAt(0, gAddressBookBundle.getString("allAddressBooks"),
> -                        kAllDirectoryRoot + "?");

Removed without replacement?

@@ -78,5 @@
>  function searchOnUnload()
>  {
> -  let abPopup = document.getElementById('abPopup');
> -  if (abPopup.getItemAtIndex(0) == (kAllDirectoryRoot + "?"))
> -    document.getElementById('abPopup').removeItemAt(0);

Removed without replacement?

::: mail/components/accountcreation/content/emailWizard.js
@@ +203,5 @@
>        _hide("provisioner_button");
>  
> +    // Add the entry for the new host to the menulist
> +    let menuitem = menulist.appendItem("", "-new-"); // label,value
> +    menuitem.serverKey = null;

Could "prepend" be used here?

::: mail/components/addrbook/content/abCommon.js
@@ -359,5 @@
> -
> -  // Make an entry for "All Address Books".
> -  if (abList) {
> -    abList.insertItemAt(0, gAddressBookBundle.getString("allAddressBooks"),
> -                        kAllDirectoryRoot + "?");

Removed without replacement?

::: mail/components/preferences/attachmentReminder.js
@@ +42,5 @@
>                                      this.bundle.getString("attachmentReminderNewText"),
>                                      input, null, {value:0});
> +    if (ok && input.value) {
> +      let newKey = this.keywordListBox.appendItem(input.value, input.value);
> +      this.keywordListBox.ensureElementIsVisible(newKey);

Please explain.

::: mail/components/preferences/display.js
@@ +24,5 @@
> +      // Prepend menuitem with empty name and value.
> +      let item = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
> +      item.setAttribute("label", "");
> +      item.setAttribute("value", "");
> +      menulist.menupopup.prepend(item);

prepend? Where is that documented? And can't it be used in case of insert at 0?

::: mailnews/addrbook/content/addrbookWidgets.xml
@@ +83,5 @@
> +            listItem.setAttribute("IsNone", "true");
> +          }
> +
> +          if (this.hasAttribute("alladdressbooks")) {
> +            // Insert a menuitem representing All addressbooks.

Nit: "All Addressbooks".
(In reply to Jorg K (GMT+1) from comment #9)
> ::: mail/base/content/ABSearchDialog.js
> @@ -63,5 @@
> >    // Initialize globals, see abCommon.js , InitCommonJS()
> >    abList = document.getElementById("abPopup");
> > -  if (abList.getItemAtIndex(0) != (kAllDirectoryRoot + "?"))
> > -    abList.insertItemAt(0, gAddressBookBundle.getString("allAddressBooks"),
> > -                        kAllDirectoryRoot + "?");
> 
> Removed without replacement?

Replaced by alladdressbooks="true" in ABSearchDialog.xul which invokes the common implementation of adding this menu entry in addrbookWidgets.xml which is also touched in this patch. The effect from this is that this item also gets the addressbook icon as other proper addressbooks. You can compare e.g. at Options-> Composition->Addressing->Default startup directory. This merges the different implementations of adding this "All addressbooks" item and styles them consistently. If the icon isn't wanted, we can change the class of the item (and again it will change consistently at all users) [needs UI review]

> @@ -78,5 @@
> >  function searchOnUnload()
> >  {
> > -  let abPopup = document.getElementById('abPopup');
> > -  if (abPopup.getItemAtIndex(0) == (kAllDirectoryRoot + "?"))
> > -    document.getElementById('abPopup').removeItemAt(0);
> 
> Removed without replacement?

The same.
 
> ::: mail/components/accountcreation/content/emailWizard.js
> @@ +203,5 @@
> >        _hide("provisioner_button");
> >  
> > +    // Add the entry for the new host to the menulist
> > +    let menuitem = menulist.appendItem("", "-new-"); // label,value
> > +    menuitem.serverKey = null;
> 
> Could "prepend" be used here?

Yes, but I avoided .prepend() where possible as it is marked experimental. Instead I reordered code where possible to use plain appendItem instead of .prepend() (.insertItemAt(0)).
 
> ::: mail/components/addrbook/content/abCommon.js
> @@ -359,5 @@
> > -
> > -  // Make an entry for "All Address Books".
> > -  if (abList) {
> > -    abList.insertItemAt(0, gAddressBookBundle.getString("allAddressBooks"),
> > -                        kAllDirectoryRoot + "?");
> 
> Removed without replacement?

Replaced by alladdressbooks="true" in abContactsPanel.xul which invokes the common implementation of adding this menu entry in addrbookWidgets.xml.

> ::: mail/components/preferences/attachmentReminder.js
> @@ +42,5 @@
> >                                      this.bundle.getString("attachmentReminderNewText"),
> >                                      input, null, {value:0});
> > +    if (ok && input.value) {
> > +      let newKey = this.keywordListBox.appendItem(input.value, input.value);
> > +      this.keywordListBox.ensureElementIsVisible(newKey);
> 
> Please explain.

The user added new keyword and it was appended to the list at the end outside of the visible part of the list. So I thought moving to the place to show that the keyword was actually added would be more sane. [needs UI review]

Similarly I improved this:
-      this.keywordListBox.removeItemAt(this.keywordListBox.selectedIndex);
-      this.keywordListBox.appendItem(input.value, input.value);
+      this.keywordListBox.selectedItem.value = input.value;
+      this.keywordListBox.selectedItem.label = input.value;

So instead of removing the current item the user is editing from the list and throwing it silently at the end of the list outside of user's visibility, I just change the current item in place. That seems more sane to me. [needs UI review]

You can try these 2 cases manually in Options->Composing->General->Keywords.
 
> ::: mail/components/preferences/display.js
> @@ +24,5 @@
> > +      // Prepend menuitem with empty name and value.
> > +      let item = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
> > +      item.setAttribute("label", "");
> > +      item.setAttribute("value", "");
> > +      menulist.menupopup.prepend(item);
> 
> prepend? Where is that documented? And can't it be used in case of insert at
> 0?

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/prepend
Yes it can be used, but I chose to avoid it where possible.
 
> ::: mailnews/addrbook/content/addrbookWidgets.xml
> @@ +83,5 @@
> > +            listItem.setAttribute("IsNone", "true");
> > +          }
> > +
> > +          if (this.hasAttribute("alladdressbooks")) {
> > +            // Insert a menuitem representing All addressbooks.
> 
> Nit: "All Addressbooks".

Thanks.
Attached patch 1459184.patch v1.1 (obsolete) — Splinter Review
I have fixed the nits and also added one SM occurrence (untested, but same code as in editor).

I have marked the potential behaviour changes by the patch in previous comment by [needs ui review]. Paenglab, please look at those places.

Thanks.
Attachment #8973367 - Attachment is obsolete: true
Attachment #8973367 - Flags: review?(jorgk)
Attachment #8973431 - Flags: ui-review?(richard.marti)
New try with the non-Calendar patch only:
https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=769566c587adaaf275d8ec0aecaf55111ff2704f
M-C at rev 51d020e4c2cb to about Gecko decision bustage from bug 1459397.
Attached patch 1459184-cal.patch v1.1 (obsolete) — Splinter Review
Removed the forgotten insert line.
Attachment #8973368 - Attachment is obsolete: true
Green try :-)

As for the prepend: What would be the replacement of |menulist.menupopup.prepend(item);| ?

Since we're busted anyway due to bug 1459397, but have a green try, we can deliberate here a bit more.

(In reply to Philipp Kewisch [:Fallen]  from comment #3)
> That aside, I believe calling
> node.insertBefore(item, null) is the same as calling appendChild. So you
> could drop the if block entirely. Please test before you do though :)
How exactly can we test this with Calender not working :-(

That aside, Philipp asked for braces {} and the indentation in Calendar is four spaces. But that all won't be necessary since
https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore says:
If the reference node is null, the specified node is added to the end of the list of children of the specified parent node.

So that code becomes just:
categoryListbox.insertBefore(item, beforeItem);  // Will append if 'beforeItem' is null.
Comment on attachment 8973431 [details] [diff] [review]
1459184.patch v1.1

This makes sense to jump to the new element. With this the user sees it was added. Would it be possible to select it too? Only when it's not too much work.
Attachment #8973431 - Flags: ui-review?(richard.marti) → ui-review+
Comment on attachment 8973431 [details] [diff] [review]
1459184.patch v1.1

Thanks, this looks like a lot of work.
Attachment #8973431 - Flags: review+
(In reply to Jorg K (GMT+1) from comment #14)
> As for the prepend: What would be the replacement of
> |menulist.menupopup.prepend(item);| ?

Maybe menulist.menupopup.insertBefore(item, menulist.menupopup.firstChild);
Should I use that for safety?
 
> So that code becomes just:
> categoryListbox.insertBefore(item, beforeItem);  // Will append if
> 'beforeItem' is null.

OK, I understand now.

(In reply to Richard Marti (:Paenglab) from comment #15)
> This makes sense to jump to the new element. With this the user sees it was
> added. Would it be possible to select it too? Only when it's not too much
> work.

Should be easy (one line).
Removed the if/else when inserting.
Attachment #8973433 - Attachment is obsolete: true
Attachment #8973464 - Flags: review+
(In reply to :aceman from comment #17)
> Maybe menulist.menupopup.insertBefore(item, menulist.menupopup.firstChild);
> Should I use that for safety?
Up to you.

> > categoryListbox.insertBefore(item, beforeItem);  // Will append if
> > 'beforeItem' is null.
> OK, I understand now.
Done in v1.2.

> Should be easy (one line).
OK, I'll wait for another patch.
I included the improvements.
Attachment #8973431 - Attachment is obsolete: true
Attachment #8973467 - Flags: review?(jorgk)
Comment on attachment 8973467 [details] [diff] [review]
1459184.patch v1.2

Thanks again.
Attachment #8973467 - Flags: review?(jorgk) → review+
Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/02e4c2f6655f
Port bug 1456611: Replace use of insertItemAt and removeItemAt methods (mail part). r=jorgk, ui-r=Paenglab
https://hg.mozilla.org/comm-central/rev/c870df0b09fa
Port bug 1456611: Replace use of insertItemAt and removeItemAt methods (calendar part). r=philipp
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 61.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: