2
|
1 const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
2
|
|
3 var gArgs = null;
|
|
4
|
|
5 function acceptRestore()
|
|
6 {
|
|
7 for (var w in gArgs.state.windows)
|
|
8 {
|
|
9 var win = gArgs.state.windows[w];
|
|
10 for (var t = win.tabs.length-1; t>=0; t--)
|
|
11 {
|
|
12 var tab = win.tabs[t];
|
|
13 if (tab._control.getAttribute("value") !== "true")
|
|
14 {
|
|
15 win.tabs.splice(t, 1);
|
|
16 if (t < win.selected)
|
|
17 win.selected--;
|
|
18 }
|
|
19 else
|
|
20 delete tab["_control"];
|
|
21 }
|
|
22 }
|
|
23 gArgs.result = true;
|
|
24 }
|
|
25
|
|
26 function addTab(parent, tab)
|
|
27 {
|
|
28 var item = document.createElementNS(XULNS, "treeitem");
|
|
29 item.setAttribute("container", "false");
|
|
30 parent.appendChild(item);
|
|
31 var row = document.createElementNS(XULNS, "treerow");
|
|
32 item.appendChild(row);
|
|
33 var cell = document.createElementNS(XULNS, "treecell");
|
|
34 if (tab.entries[tab.index-1].title)
|
|
35 cell.setAttribute("label", tab.entries[tab.index-1].title);
|
|
36 else
|
|
37 cell.setAttribute("label", "(Untitled)");
|
|
38 cell.setAttribute("editable", "false");
|
|
39 row.appendChild(cell);
|
|
40 cell = document.createElementNS(XULNS, "treecell");
|
|
41 cell.setAttribute("value", "true");
|
|
42 row.appendChild(cell);
|
|
43 tab._control = cell;
|
|
44 }
|
|
45
|
|
46 function addWindow(parent, win)
|
|
47 {
|
|
48 var item = document.createElementNS(XULNS, "treeitem");
|
|
49 item.setAttribute("container", "true");
|
|
50 item.setAttribute("open", "true");
|
|
51 parent.appendChild(item);
|
|
52 var row = document.createElementNS(XULNS, "treerow");
|
|
53 item.appendChild(row);
|
|
54 var cell = document.createElementNS(XULNS, "treecell");
|
|
55 cell.setAttribute("label", "Window");
|
|
56 cell.setAttribute("editable", "false");
|
|
57 row.appendChild(cell);
|
|
58 cell = document.createElementNS(XULNS, "treecell");
|
|
59 cell.setAttribute("editable", "false");
|
|
60 row.appendChild(cell);
|
|
61 var children = document.createElementNS(XULNS, "treechildren");
|
|
62 item.appendChild(children);
|
|
63 for (var i in win.tabs)
|
|
64 addTab(children, win.tabs[i]);
|
|
65 }
|
|
66
|
|
67 function loadState(event)
|
|
68 {
|
|
69 gArgs = window.arguments[0];
|
|
70 var parent = document.getElementById("treechildren");
|
|
71 var windows = gArgs.state.windows;
|
|
72 for (var i in windows)
|
|
73 addWindow(parent, windows[i]);
|
|
74 }
|
|
75
|
|
76 window.addEventListener("load", loadState, false);
|
|
77 |