Commits

Anonymous committed 9c65e60

'ignore group position' seems like it may actually be working now! Famous last words?
Tabs still aren't in quite the proper order on restart using it though, ugh.

Comments (0)

Files changed (3)

chrome/content/gst.debug.js

 		
 	function assert(condition, message) {
 		if (condition) return;
-		log("ASSERTION FAILURE: " + message, 4);
-		if (GST.debug)
-			alert("ASSERTION FAILURE: " + message);
+		log("ASSERTION FAILURE " + (GST.debug ? "(RESTART!): " : ": ") + message, 4);
+		if (GST.debug) {
+			alert("ASSERTION FAILURE (RESTART!): " + message);
+			GST = null;	// halts everything
+		}
 	}
 	
 	function log(message, stackPos) {

chrome/content/gst.event.js

 		},
 	
 		onLocationChange : function progress_onLocationChange(browser, webProgress, request, uri) {
+			if (!GST.ssTabsOpened) return;
 			let tab = getTabForBrowser(browser);
 			GST.sortedList.update(tab, GST.sort.HOSTNAME, uri.asciiHost);		// HOSTNAME
 			GST.sortedList.update(tab, GST.sort.LAST_BROWSED, Date.now());		// LAST BROWSED (DATE_DAY, DATE_SESSION)
-			
-			// first tab won't always fire onLocationChange to completion... bug? My mistake/misunderstanding?
-			// Seems to have something to do with it being the primary browser...? If you restore Firefox with only one tab,
-			// then onLocationChange will not fire at all.
-			let hostProp = gBrowser.tabs[0][GST.props[GST.sort.HOSTNAME]];
-			if (hostProp === undefined || hostProp === "") {
-				let host = gBrowser.tabs[0].linkedBrowser.currentURI.asciiHost;
-				if (host !== hostProp)
-					GST.sortedList.update(gBrowser.tabs[0], GST.sort.HOSTNAME, host);
-			}
 		},
 	
 		onStateChange : function() { return 0; },
 	},
 	
 	onTabOpen : function(event) {
+		if (!GST.ssTabsOpened) return;	// tabs aren't finished restoring
 		let tab = event.originalTarget;
-		if (GST.ssTabsOpened) {	// if tabs are finished restoring
-			GST.setTabSource(tab);		// (SOURCE)
-			GST.sortedList.update(tab, GST.sort.LAST_OPENED, Date.now());		// LAST OPENED
-		}
-	},
-	
-	onTabRestore : function(event) {
-		let tab = event.originalTarget;
-		for each (let prop in GST.props) {
-		    if (prop.length > 0)
-			tab[prop] = GST.ss.getTabValue(tab, prop);
-		}
-		GST.sortedList.update(tab, GST.sort.LAST_OPENED, tab.gstLastOpened);		// LAST OPENED
+		GST.setTabSource(tab);		// (SOURCE)
+		GST.sortedList.update(tab, GST.sort.LAST_OPENED, Date.now());		// LAST OPENED
 	},
 	
 	onTabClose : function(event) {
 	},
 	
 	onTitleChange : function(event) {
+		if (!GST.ssTabsOpened) return;
 		let document = event.target;
 		let tabIdx = gBrowser.getBrowserIndexForDocument(document);
 		if (tabIdx === -1) return;
 		let tab = gBrowser.tabs[tabIdx];
-		
-		// onTitleChange seems to fire sometimes with document.title being "" when
-		// the tab label itself clearly has a value, and nothing particularly strange going on
-		// is this natural, or some kind of bug?
+
+		// onTitleChange fires with 'document.title' being blank sometimes when tab has a label and everything, I don't know why...
 		let title = document.title;
 		if (title || !tab.gstTitle)
 			GST.sortedList.update(tab, GST.sort.TITLE, title);		// TITLE
 	
 	ssOpenedObserver : {
 		observe : function ssOpenedObserver_observe(aSubject, aTopic, aData) {
+			// this function fires after all the tabs being restored are opened,
+			// but they are still restoring
+			
+			for (let i = 0; i < gBrowser.tabs.length; i++) {
+				let tab = gBrowser.tabs[i];
+				for each (let prop in GST.props)
+					tab[prop] = GST.ss.getTabValue(tab, prop);
+			}
+			
+			GST.sortedList.fullSort();
 			GST.ssTabsOpened = true;
 		}
 	}
 gBrowser.tabContainer.addEventListener("TabOpen", GST.event.onTabOpen, false);
 gBrowser.tabContainer.addEventListener("TabClose", GST.event.onTabClose, false);
 gBrowser.addEventListener("DOMTitleChanged", GST.event.onTitleChange, false);
-gBrowser.tabContainer.addEventListener("SSTabRestoring", GST.event.onTabRestore, false);
 Services.obs.addObserver(GST.event.ssOpenedObserver, "sessionstore-windows-restored", false);
 GST.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
 GST.prefs.addObserver("doFullSortNow", GST.event.prefObserver, false);

chrome/content/gst.list.js

 			if (tab.gstSortGroup.length === 1) return null;
 			for (let i = 0; i < tab.gstSortGroup.length; i++) {
 				let similarTab = tab.gstSortGroup[i];
-				if (similarTab === tab) continue;
-				if (similarTab.gstPosGroup) return similarTab;
+				if (similarTab !== tab) {
+					if (similarTab.gstPosGroup)
+						return similarTab;
+				}
 			}
 			return null;
 		}
 		
-		let isSingleTab = (tab.gstPosGroup && tab.gstPosGroup.length === 2);
-		if (isSingleTab)
-			tab.gstPosGroup.gstIsUniform = false;
-		removeTab(tab, posList);
-		
-		let matchTab = getMatchingTab(tab);
-		let lastGroup, matchGroup;
-		if (posList.length > 0)
-			lastGroup = posList[posList.length - 1];
-
-		if (!lastGroup || !matchTab && lastGroup.gstIsUniform) {
-			let group = [tab];
-			posList.push(group);
-			tab.gstPosGroup = group;
-			return;
-		}
-		
-		if (matchTab) matchGroup = matchTab.gstPosGroup;
-		if (matchTab && !matchGroup.gstIsUniform) {
+		function splice(matchGroup) {
 			let leftGroup, rightGroup;
 			let matchTabIdx = matchGroup.indexOf(matchTab);
 			let midGroup = matchGroup.splice(matchTabIdx, 1);
-			if (matchTabIdx < matchGroup.length)	// remember our length is now - 1
+			if (matchTabIdx < matchGroup.length)	// remember our length is now 1 less
 				rightGroup = matchGroup.splice(matchTabIdx);
 			if (matchTabIdx > 0)
 				leftGroup = matchGroup;
 
-			midGroup.push(tab);
 			matchTab.gstPosGroup = midGroup;
-			tab.gstPosGroup = midGroup;
-			doSortList(midGroup, GST.sortBy.getSort());
 			midGroup.gstIsUniform = true;
 			
 			let matchGroupIdx = posList.indexOf(matchGroup);
 			posList.splice(matchGroupIdx, 1, midGroup);
 			if (rightGroup) posList.splice(matchGroupIdx + 1, 0, rightGroup);
 			if (leftGroup) posList.splice(matchGroupIdx, 0, leftGroup);
-			return;
+			return midGroup;
+		}
+
+		let group;
+		let matchTab = getMatchingTab(tab);
+		if (matchTab) {
+			let matchGroup = matchTab.gstPosGroup;
+			if (!matchGroup.gstIsUniform)
+				group = splice(matchGroup);
+			else if (tab.gstPosGroup !== matchGroup)
+				group = matchGroup;
+		} else if (!tab.gstPosGroup) {
+			let lastGroup;
+			if (posList.length > 0)
+				lastGroup = posList[posList.length - 1];
+			if (!lastGroup || lastGroup.gstIsUniform) {
+				group = [];
+				posList.push(group);
+			} else
+				group = lastGroup;
 		}
 		
-		let group;
-		// add matching tabs to homogenous groups,
-		// and non-matching tabs to heterogenous groups
-		if (matchTab && matchGroup.gstIsUniform)
-			group = matchGroup;
-		else if (!matchTab && !lastGroup.gstIsUniform)
-			group = lastGroup;
-		else return;
-
-		group.push(tab);
-		tab.gstPosGroup = group;
-		doSortList(group, GST.sortBy.getSort());
+		let lenBefore = getListLen(posList);
+		if (group) {
+			let toBeSingle = (tab.gstPosGroup && tab.gstPosGroup.length === 2);
+			if (toBeSingle)	tab.gstPosGroup.gstIsUniform = false;
+			removeTab(tab, posList);
+			
+			tab.gstPosGroup = group;
+			tab.gstPosGroup.push(tab);
+		}
+		doSortList(tab.gstPosGroup, GST.sortBy.getSort());
+		let lenAfter = getListLen(posList);
+		GST.assert(lenAfter >= lenBefore, "Net fewer tabs after addPosTab()");
 	}
 	
 	function removeTab(tab, list) {
 			for (let j = 0; j < list[i].length; j++) {
 				let tab = list[i][j];
 				if (tab._tPos !== idx) {
-					GST.halt = true;
+					//GST.halt = true;
 					GST.assert(tab._tPos === idx, "Position check failure: " + idx + " " + tab._tPos);
 				}
 				idx++;
 	
 	let that = {
 		update : function(tab, sortable, value) {
-			if (GST.halt) return;
+			GST.assert(GST.ssTabsOpened, "Tab update occurring before restoring tabs have finished opening.");
+			//if (GST.halt) return;
 			let sortableProp = GST.props[sortable]
 			tab[sortableProp] = value;
 			// save in session store
 			let list = getList();
 			positionTab(tab, list);
 			print(list, sortableProp);
+			GST.assert(getListLen(getList()) === gBrowser.tabs.length, "List isn't correct length."); 
 		},
 		
 		removeTab : function(tab) {
 			removeTab(tab, posList);
 		},
 		
+		report : function() {
+			GST.log("-------- REPORT --------");
+			print(getList(), GST.props[getSort()]);
+			print(getList(), GST.props[GST.isSortBetween ? GST.sortBy.getSort() : GST.sortWithinBy.getSort()]);
+			GST.log("-------- END REPORT --------");
+			GST.assert(getListLen(getList()) === gBrowser.tabs.length, "List isn't correct length."); 
+		},
+		
 		fullSort : function() {
 			clearLists();
 			
 				addPosTab(tab);
 				positionTab(tab, list);
 			}
-			GST.assert(getListLen(list) === gBrowser.tabs.length, "List isn't correct length.");
-			print(list, GST.props[GST.isSortBetween ? GST.sortBy.getSort() : GST.sortWithinBy.getSort()]);
+			this.report();
 			positionCheck(list);
 		}
 	};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.