Hi, John. First, thanks.. comments below. On Jan 5, 5:37 am, John J Barton <[email protected]> wrote: > On Jan 4, 5:05 pm, Tatablack <[email protected]> wrote: > > > Hi, all. > > > I'm working on a Firebug extension meant to "beautify" JavaScript code > > as shown in the Script and Net panels (the beautifying work is done by > > the JS Beautifier library). > > The Net Panel stuff is finished (just one glitch left to be sorted > > out). I'm not sure which is the best way to go with the script panel, > > and that's why I'm here. > > I'm sorry if some of what I'll write may sound confused - it probably > > is, given that I'm still trying to understand Firebug's internals. > > > I added a button in the Script toolbar, just to the right of the > > "fbLocationList" combo (the one showing available JS files). > > To the left would be more in keeping with the design...
In that toolbar, I see: fbScriptFilterMenu fbLocationSeparator fbLocationList fbDebuggerButtons Do you think that the new button should be placed between fbLocationSeparator and fbLocationList? > > Clicking the button, I'm able to get the currently displayed JS text, > > like this: > > > context.sourceCache.loadText(context.panelMap.script.location.href) > > I'm not sure where you are putting your code, but in a panel it would > be this.context and this.location. Especially the second expression is > quite odd. The code is executed when clicking on the new toolbar button. In the XUL source, the oncommand attribute of the toolbarbutton is: oncommand="Firebug.FireBeautyModule.beautifyScript(FirebugContext)" So, what I have is the context. I'm not sure if I can pass something besides FirebugContext... may I? As to the second expression, I'll turn that into a question: if all I have is the context, how can I get the current panel and its location? > > ...and beautify it. Now I have to replace the currently displayed file > > with the beautified version. Questions arise... > > 1. I understand that there's a sourceCache object storing, I believe, > > all loaded source files (HTML, JS, and so on). Should I leave the > > cache alone, or update it with the beautified text (in case it's an > > external JS file, of course)? > > Better leave it. Plus I don't know how you can replace it: the > sourceFile objects hold unrendered text and I guess you want decorated > (colored) text? No, sorry - I know there's already FireRainbow which does syntax highlighting. What I mean by "beautifying" is actually reformatting packed/minified code, adding line breaks, indentation, and so on. > > 2. I saw that there's a sourceFileMap, used to access different types > > of SourceFile objects, created by parsing <script> tags, included JS > > files, and probably other things I'm not quite sure about. Should I > > create a new SourceFile object, and use it to replace the one with the > > same href in the sourceFileMap? If so, how can I know which kind of > > SourceFile object to create? > > Better not. Firebug assumes that the sourceFileMap is the one it > built. Thought so. :-/ > > 3. Moreover, I see that, after choosing another file from the > > fbLocationList combo, the script panel contents are refreshed by > > calling the navigate(object) method of the panel, passing as "object" > > the value of "locationList.repObject" (happens in chrome.js). How is > > this related to the SourceFile currently displayed? (I tried to get at > > it, but ChromeBug crashed on me after trying to access it while at a > > breakpoint) > > The object navigate(object) will be the same type as the > this.location, for every panel. So you can look at the functions like > getLocationList() to see that yes, the SourceFile is the location type > for Script panel. > > (By 'crashed' you mean exited with a crashreport?) Erm, as of an hour ago, yes, sure. :-) > > That is, more or less, where I am poking at now. Any help would be > > greatly appreciated. > > Just to point out that the SourceBox used in the Script file is > designed to support beautifier-like tools, that is any tool that wants > to decorate the source. The script panel only shows a viewport full of > the source at any one time. So if you have 65,000 line of source and a > window that can show 40 lines, the SourceBox arranges to show 40 at a > time. All 65kloc cannot be rendered at once. So a beautifier (or > decompressor) like tool would implement SourceBoxDecorator and chain > the Script panel function getDecorator(). (By chain I mean ensure that > the previous object in getDecorator is called just before your decorate > (). I realized there was a viewport, but were not sure how to use the decorator. It sounds promising, though; I'm gonna try with that. Thanks again. -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/firebug?hl=en.
