Closed Bug 772371 Opened 14 years ago Closed 14 years ago

"Delete node" option should be disabled when the operation is not allowed anymore

Categories

(DevTools :: Inspector, defect)

14 Branch
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: sbadau, Assigned: joejoevictor)

Details

(Whiteboard: [good first bug][mentor=paul][lang=js][check-if-fixed-because-toolbox])

Attachments

(1 file, 7 obsolete files)

Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0 When the deletion of a node is not allowed, the option to "Delete node" should be grayed out to avoid user confusion. Please see Bug 760171, Comment 18 and 19. Reproducible: always Steps to reproduce: 1. Load the about: page 2. Right click on the page and from the context menu select Inspect Element 3. Click on the "Node Operations" button (triangle facing down). 4. Click "Delete Node". 5. After step 4 the "html" node is displayed, click on the "Node Operation" and select "Delete Node" Expected results: The deletion of the "html" node is not allowed, the "Delete node" option is grayed out. Actual results: "Delete node" node option is still available.
Whiteboard: [good first bug][mentor=paul][lang=js]
I'm new to mozilla open source community. I'm looking for some easy bugs to work on so that i can get familiar with the mozilla codebase. Can I work on this bug?
Yes!
Assignee: nobody → joejoevictor
(In reply to Paul Rouget [:paul] from comment #1) > This should happen somewhere in this function: > http://mxr.mozilla.org/mozilla-central/source/browser/devtools/highlighter/ > highlighter.jsm#634 Just for curiosity, how do you locate a specific piece of buggy code? Say for example, how do you know this bug is located in the location in the link above? I'm just curious how a general bug fixing process starts. Thx.
(In reply to Zuhao(Joe) Chen from comment #4) > (In reply to Paul Rouget [:paul] from comment #1) > > This should happen somewhere in this function: > > http://mxr.mozilla.org/mozilla-central/source/browser/devtools/highlighter/ > > highlighter.jsm#634 > > Just for curiosity, how do you locate a specific piece of buggy code? Say > for example, how do you know this bug is located in the location in the link > above? I'm just curious how a general bug fixing process starts. Thx. Different people use different approaches and Paul is intimately familiar with the code in question, but here is a blog post that goes over the whole process: https://blog.mozilla.org/jorendorff/2011/04/18/how-to-fix-a-bug-episode-434494-part-1/
I've added a dump function inside the update function in http://mxr.mozilla.org/mozilla-central/source/browser/devtools/highlighter/highlighter.jsm#637 . Here's the pastebin http://pastebin.mozilla.org/1743344 . Then I rebuild the browser devtools using "make -s -C browser/devtools" under obj-xx-xxx directory but it seems the dump function is not getting called or something when I tried to inspect about: page using inspector. Is it because I didn't use dump function correctly or I didn't rebuild the browser correctly?
You may need to set browser.dom.window.dump.enabled to true in about:config.
(In reply to Josh Matthews [:jdm] from comment #7) > You may need to set browser.dom.window.dump.enabled to true in about:config. I've double checked that config and it's been set to true. Thx tough. Any other suggestion?
Hey Joe, On line 3 of your pastebin, you should remove the 'aNode.' part of the statement. The dump function is global.
(In reply to Jared Wein [:jaws] from comment #9) > Hey Joe, > > On line 3 of your pastebin, you should remove the 'aNode.' part of the > statement. The dump function is global. Seems it still not outputting the message in console after taken the aNode out...
Which console are you looking in? Dump outputs to the system terminal, not the Firefox error console or web console.
(In reply to Josh Matthews [:jdm] from comment #11) > Which console are you looking in? Dump outputs to the system terminal, not > the Firefox error console or web console. I'm looking at system terminal.
Should I try rebuild the whole mozilla-central?
Are you running a debug build or an optimized build? Your .mozconfig should look something like this: ac_add_options --enable-application=browser ac_add_options --enable-debug ac_add_options --disable-optimize ac_add_options --enable-tests
(In reply to Jared Wein [:jaws] from comment #14) > Are you running a debug build or an optimized build? > > Your .mozconfig should look something like this: > ac_add_options --enable-application=browser > ac_add_options --enable-debug > ac_add_options --disable-optimize > ac_add_options --enable-tests I'm running a debug build. Got it working after rebuild the whole mozilla-central. Anyway, thank you, Jared.
If you're on Mac, you also need to rebuild browser/app > make -s -C browser/devtools && make -s -C browser/app
http://pastebin.mozilla.org/1746520 I try to grey out the menuitem by setting its attribute disabled to true if its a root element but it doesn't really work. Any suggestion?
(In reply to Zuhao(Joe) Chen from comment #17) > http://pastebin.mozilla.org/1746520 I try to grey out the menuitem by > setting its attribute disabled to true if its a root element but it doesn't > really work. Any suggestion? Just realize getDocumentElement() isn't the right function, I used documentElement instead http://pastebin.mozilla.org/1746522 . The menu item is still not grey-outed.
I think your code actually work, but not for the menu in the infobar. There are 2 "delete node" menuitems: 1) in the infobar (the one you're trying to modify) 2) in the Markup Panel (button on the left of the node list at the bottom of the page). Do a right click on any node, you'll see the delete button. I suggest that you add a "popupshowing" event listener (or "onpopupshowing" attribute) on both menus, and then, in the listener, update the menuitem. Here are some examples: http://mxr.mozilla.org/mozilla-central/search?string=popupshowing This makes this patch a little less trivial that I thought (but still not too hard), so please let me know if this is not clear. Also, did you fix your build problem? Incremental builds should take 10 seconds max. Thank you for working on that :) For the next iteration: can you please attach a patch instead? It's easier to read your code when it's a patch/diff.
(In reply to Paul Rouget [:paul] from comment #19) > I think your code actually work, but not for the menu in the infobar. > There are 2 "delete node" menuitems: > 1) in the infobar (the one you're trying to modify) > 2) in the Markup Panel (button on the left of the node list at the bottom of > the page). Do a right click on any node, you'll see the delete button. > > I suggest that you add a "popupshowing" event listener (or "onpopupshowing" > attribute) on both menus, and then, in the listener, update the menuitem. > Thank you for the advise, Paul. I will try that way. For the build problem, I think it's because I didn't build browser/app. I'm using mac so I guess that causes the problem. Sure, I didn't know which way is more convenient to you. I will just upload a patch next time. Sorry about the confusion. > Here are some examples: > http://mxr.mozilla.org/mozilla-central/search?string=popupshowing > > This makes this patch a little less trivial that I thought (but still not > too hard), so please let me know if this is not clear. > > Also, did you fix your build problem? Incremental builds should take 10 > seconds max. > > Thank you for working on that :) > > For the next iteration: can you please attach a patch instead? It's easier > to read your code when it's a patch/diff.
Attached patch patch for bug772371 (obsolete) — — Splinter Review
I moved my comparison statement into the popupshowing listener of menu but when I tried to compare DOM root element and the selected html root node they somehow aren't the same object. Should I use other mechanism to check if the root node is selected?
Attachment #650674 - Flags: review?(paul)
Attached patch patch for bug772371 (obsolete) — — Splinter Review
Just realize getElementByID can only be used by document object. Tried another way of getting child of menu. Still doesn't seem to work.
Attachment #650674 - Attachment is obsolete: true
Attachment #650674 - Flags: review?(paul)
Attached patch patch for bug772371 (obsolete) — — Splinter Review
Tried using class name for retrieving delete node menuitem. Still not able to disable it.
Attachment #650685 - Attachment is obsolete: true
Attachment #650996 - Flags: review?
http://pastebin.mozilla.org/1749363 The method I used here does change the label but it just don't work when i change the setAttribute("disabled", "true")...sigh...
Try to do that on the command directly (commands element broadcast the value of their attributes): > let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); > cmd.setAttribute("disabled", "true");
Attached patch patch for bug-772371 (obsolete) — — Splinter Review
cmd works but I still don't really understand what's behind this.
Attachment #650996 - Attachment is obsolete: true
Attachment #650996 - Flags: review?
Attachment #651030 - Flags: review?(paul)
Attached patch patch for bug-772371 (obsolete) — — Splinter Review
Move code snippet into updateInfobar function for better checking.
Attachment #651030 - Attachment is obsolete: true
Attachment #651030 - Flags: review?(paul)
Attachment #651042 - Flags: review?
Comment on attachment 651042 [details] [diff] [review] patch for bug-772371 Review of attachment 651042 [details] [diff] [review]: ----------------------------------------------------------------- In response to comment #26, you can read https://developer.mozilla.org/en-US/docs/XUL_Tutorial/Commands to learn more about XUL commands. ::: browser/base/content/browser.xul @@ +282,5 @@ > accesskey="&inspectorHTMLCopyOuter.accesskey;" > command="Inspector:CopyOuter"/> > <menuseparator/> > <menuitem id="inspectorHTMLDelete" > + class="inspectorHTMLDelete" This class isn't necessary. ::: browser/devtools/highlighter/highlighter.jsm @@ +640,5 @@ > + // Added by Joe > + let DOMroot = this.node.ownerDocument.documentElement; > + if(this.node == DOMroot){ > + let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); > + cmd.setAttribute("disabled", "true"); This could probably be simpler if it was: let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); cmd.setAttribute("disabled", this.node == this.node.ownerDocument.documentElement); If it is done this way, then you can remove the if/else clauses and also the DOMroot variable.
Attachment #651042 - Flags: review? → feedback+
Comment on attachment 651042 [details] [diff] [review] patch for bug-772371 Thanks for that patch! ># HG changeset patch ># Parent b5ae446888f54480e2d20e59dc1b8723799a5cbb ># User Zuhao(Joe) Chen <joejoevictor@gmail.com> >Bug-772371 fix > <menuitem id="inspectorHTMLDelete" >+ class="inspectorHTMLDelete" > label="&inspectorHTMLDelete.label;" > accesskey="&inspectorHTMLDelete.accesskey;" > command="Inspector:DeleteNode"/> > […] > > let fragment = this.buildPseudoClassMenu(); >+ > menu.appendChild(fragment); > }.bind(this), true); […] > container.appendChild(arrowBoxBottom); >- >+ > aParent.appendChild(container); This needs some cleanup. > updateInfobar: function Highlighter_updateInfobar() > { >+ // Added by Joe >+ let DOMroot = this.node.ownerDocument.documentElement; We are not always sure that this.node has an ownerDocument. If no ownerDocument, disable the menuitem. >+ if(this.node == DOMroot){ >+ let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); >+ cmd.setAttribute("disabled", "true"); >+ } >+ else >+ { >+ let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); >+ cmd.setAttribute("disabled", "false"); >+ } You can move this line above the block: >+ let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); Use: > cmd.removeAttribute("disabled") instead of: > cmd.setAttribute("disabled", "false"); --- Why does it work? Because a <command> behaves like a <broadcaster>. A <broadcaster> "forward" its attributes to the element. See: https://developer.mozilla.org/en-US/docs/XUL/broadcaster So when you do: <command foo="bar" id="cmd1234> and: <box command="cmd1234"> Automatically, the box gets an foo="bar" attribute. That's it :)
Attached patch latest patch for bug 772371 (obsolete) — — Splinter Review
Jared and Paul, thank you so much for your feedback. Here's the latest patch.
Attachment #651042 - Attachment is obsolete: true
Hey Joe, please request review on your patches to make sure that they get looked at.
Status: NEW → ASSIGNED
Hardware: x86 → All
Attached patch patch for bug 72371 (obsolete) — — Splinter Review
Repost patch with review request. Sorry about the missing review request.
Attachment #651957 - Attachment is obsolete: true
Attachment #652030 - Flags: review?(paul)
Attachment #652030 - Flags: review?(jaws)
Comment on attachment 652030 [details] [diff] [review] patch for bug 72371 Review of attachment 652030 [details] [diff] [review]: ----------------------------------------------------------------- ::: browser/devtools/highlighter/highlighter.jsm @@ +638,5 @@ > { > + // Added by Joe > + let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); > + if(this.node.ownerDocument.documentElement && this.node == this.node.ownerDocument.documentElement) > + cmd.setAttribute("disabled", "true"); comment #29 says that ownerDocument may be null, so this should be changed to: > if (this.node.ownerDocument && this.node == this.node.ownerDocument.documentElement) { > ... > } else ... @@ +641,5 @@ > + if(this.node.ownerDocument.documentElement && this.node == this.node.ownerDocument.documentElement) > + cmd.setAttribute("disabled", "true"); > + else > + cmd.removeAttribute("disabled"); > + nit: please remove this extra whitespace characters on this line.
Attachment #652030 - Flags: review?(jaws) → feedback+
Thanks for the feedback. :) (In reply to Jared Wein [:jaws] from comment #33) > Comment on attachment 652030 [details] [diff] [review] > patch for bug 72371 > > Review of attachment 652030 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: browser/devtools/highlighter/highlighter.jsm > @@ +638,5 @@ > > { > > + // Added by Joe > > + let cmd = this.chromeDoc.getElementById("Inspector:DeleteNode"); > > + if(this.node.ownerDocument.documentElement && this.node == this.node.ownerDocument.documentElement) > > + cmd.setAttribute("disabled", "true"); > > comment #29 says that ownerDocument may be null, so this should be changed > to: > > if (this.node.ownerDocument && this.node == this.node.ownerDocument.documentElement) { > > ... > > } else ... > > @@ +641,5 @@ > > + if(this.node.ownerDocument.documentElement && this.node == this.node.ownerDocument.documentElement) > > + cmd.setAttribute("disabled", "true"); > > + else > > + cmd.removeAttribute("disabled"); > > + > > nit: please remove this extra whitespace characters on this line.
Minor correction after Jared's feedback.
Attachment #652030 - Attachment is obsolete: true
Attachment #652030 - Flags: review?(paul)
Attachment #652035 - Flags: review?(paul)
So I have been thinking… Another menuitem uses this command. The context menu in the markup view. The targeted node is not `this.node` in this case (I forget about that). So if the command is disabled because the root node is selected, then it will be impossible to delete a non-selected node in the markup panel. I'm sorry, I'm the one who suggested this original method. Give me sometime, I'll think about the right approach here.
(In reply to Paul Rouget [:paul] from comment #36) > So I have been thinking… > > Another menuitem uses this command. The context menu in the markup view. The > targeted node is not `this.node` in this case (I forget about that). > > So if the command is disabled because the root node is selected, then it > will be impossible to delete a non-selected node in the markup panel. > > I'm sorry, I'm the one who suggested this original method. > > Give me sometime, I'll think about the right approach here. I've noticed this problem too. Can we try using different listeners in highlighter and tree panel to achieve this purpose?
(In reply to Zuhao(Joe) Chen from comment #37) > (In reply to Paul Rouget [:paul] from comment #36) > > So I have been thinking… > > > > Another menuitem uses this command. The context menu in the markup view. The > > targeted node is not `this.node` in this case (I forget about that). > > > > So if the command is disabled because the root node is selected, then it > > will be impossible to delete a non-selected node in the markup panel. > > > > I'm sorry, I'm the one who suggested this original method. > > > > Give me sometime, I'll think about the right approach here. > > I've noticed this problem too. Can we try using different listeners in > highlighter and tree panel to achieve this purpose? Different "onpopupshowing"?
Attachment #652035 - Flags: review?(paul)
Any update on this?
Flags: needinfo?(joejoevictor)
I suggest that we pause this bug for the moment as the inspector menus are being completely rewritten (toolbox project, see http://paulrouget.com/e/devtools-toolbox/).
Flags: needinfo?(joejoevictor)
Whiteboard: [good first bug][mentor=paul][lang=js] → [good first bug][mentor=paul][lang=js][check-if-fixed-because-toolbox]
Fixed by our work on the inspector refactoring.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → WORKSFORME
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: