1 sdump('D_TRACE','Loading app_shell.js\n');
3 function app_shell_init(p) {
4 dump("TESTING: app_shell.js: " + mw.G['main_test_variable'] + '\n');
6 p.w.close_tab = function (t1,t2) { return close_tab(p.d,t1,t2); };
7 p.w.find_free_tab = function (tabs) { return find_free_tab(tabs); };
8 p.w.new_tab = function () { return new_tab(p.d,p.tabbox); };
9 p.w.replace_tab = function (label,chrome,params) { return replace_tab(p.d,p.tabbox,label,chrome,params); };
11 p.w.replace_tab('Tab','chrome://evergreen/content/main/about.xul');
14 function close_tab( d, t1, t2 ) {
15 // t1 = tabbox or tab, if t1 = tabbox, t2 = tab index, otherwise close current tab
16 sdump('D_TAB',arg_dump(arguments,{1:true,2:true}));
17 if (typeof(t1)!='object')
18 t1 = d.getElementById(t1);
19 if (typeof(t1)!='object')
20 throw('Could not find tab or tabbox. d = ' + d + ' tabbox = ' + t1 + '\n');
24 if (t1.tagName == 'tabbox')
27 tabbox = t1.parentNode.parentNode;
29 var idx = tabbox.selectedIndex;
33 sdump('D_TAB','tabbox.selectedIndex = ' + tabbox.selectedIndex + '\n');
34 var tabs = tabbox.firstChild;
35 var panels = tabbox.lastChild;
39 tabs.advanceSelectedTab(+1);
41 dump('failed tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
43 tabs.advanceSelectedTab(-1);
45 dump('failed again tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
50 tabs.advanceSelectedTab(-1);
52 dump('failed tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
54 tabs.advanceSelectedTab(+1);
56 dump('failed again tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
62 sdump('D_TAB','\tnew tabbox.selectedIndex = ' + tabbox.selectedIndex + '\n');
64 tabs.childNodes[ idx ].hidden = true;
65 sdump('D_TAB','tabs.childNodes[ ' + idx + ' ].hidden = true;\n');
67 // Make sure we keep at least one tab open.
69 for (var i = 0; i < tabs.childNodes.length; i++) {
70 var tab = tabs.childNodes[i];
83 function find_free_tab(tabs) {
84 var last_not_hidden = -1;
85 for (var i = 0; i<tabs.childNodes.length; i++) {
86 var tab = tabs.childNodes[i];
90 if (last_not_hidden == tabs.childNodes.length - 1)
92 // If the one next to last_not_hidden is hidden, we want it.
93 // Basically, we fill in tabs after existing tabs for as
95 var idx = last_not_hidden + 1;
96 var candidate = tabs.childNodes[ idx ];
99 // Alright, find the first hidden then
100 for (var i = 0; i<tabs.childNodes.length; i++) {
101 var tab = tabs.childNodes[i];
108 function new_tab( d, tabbox ) {
109 sdump('D_TAB',arg_dump(arguments));
110 if (typeof(tabbox)!='object')
111 tabbox = d.getElementById(tabbox);
112 if (typeof(tabbox)!='object')
113 throw('Could not find tabbox. d = ' + d + ' tabbox = ' + tabbox + '\n');
114 var tabs = tabbox.firstChild;
115 var panels = tabbox.lastChild;
116 var tc = find_free_tab(tabs);
117 sdump('D_TAB','find_free_tab returned ' + tc + '\n');
118 if (tc == -1) { return; } // let's only have up to 10 tabs
119 var tab = tabs.childNodes[ tc ];
120 tab.setAttribute('label','Tab ' + (tc + 1) );
123 tabs.selectedIndex = tc;
124 replace_tab(d,tabbox,'Tab','chrome://evergreen/content/main/about.xul');
126 dump('+++++++++++++++++++++++++++++' + E + ' : ' + js2JSON(E)+'\n');
130 function replace_tab( d, tabbox, label, chrome, params ) {
131 sdump('D_TAB',arg_dump(arguments,{2:true,3:true,4:true}));
132 if (typeof(tabbox)!='object')
133 tabbox = d.getElementById(tabbox);
134 if (typeof(tabbox)!='object')
135 throw('Could not find tabbox. d = ' + d + ' tabbox = ' + tabbox + '\n');
136 var tabs = tabbox.firstChild;
137 var panels = tabbox.lastChild;
139 var idx = tabs.selectedIndex;
140 var tab = tabs.childNodes[ idx ];
141 var panel = panels.childNodes[ idx ];
144 tab.setAttribute('label',label + ' ' + (idx+1));
146 var frame = d.createElement('iframe');
147 frame.setAttribute('id','frame_'+idx);
148 frame.setAttribute('flex','1');
149 frame.setAttribute('src',chrome);
150 panel.appendChild(frame);
151 panel.replaceChild(panel.lastChild,panel.firstChild);
153 sdump('D_TAB','Created frame : ' + frame.id + ' for index : ' + idx + ' with src=' + frame.getAttribute('src') + '\n');
154 //frame.contentWindow.parentWindow = parentWindow;
155 //frame.contentWindow.tabWindow = this;
156 //dump('replace_tab.tabWindow = ' + this + '\n');
157 frame.contentWindow.mw = mw;
158 //frame.contentWindow.am_i_a_top_level_tab = true;
160 frame.contentWindow.params = params;
162 return frame.contentWindow;
164 dump(js2JSON(E)+'\n');
166 //debug_tabs(d,tabbox);