Skip to content

Commit

Permalink
Cleanup search bar after closing of last private tab in window
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Feb 11, 2014
1 parent f18144a commit 3002ccd
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var windowsObserver = {
_log(topic + " => forgetAllClosedTabs()");
this.forgetAllClosedTabs();
}
this.clearSearchBar();
this.clearSearchBars();
}.bind(this), 0, timer.TYPE_ONE_SHOT);
}
},
Expand Down Expand Up @@ -1171,26 +1171,33 @@ var windowsObserver = {
if(
window.privateTab._checkLastPrivate
&& this.isPrivateTab(tab)
&& this.isLastPrivate(tab)
) {
_log("Closed last private tab");
if(this.forbidCloseLastPrivate()) {
var pos = "_tPos" in tab
? tab._tPos
: Array.indexOf(window.gBrowser.tabs, tab); // SeaMonkey
this.openNewPrivateTab(window, false, function(newTab) {
newTab && window.gBrowser.moveTabTo(newTab, pos);
});
}
else if(
this.isSeaMonkey
&& prefs.get("rememberClosedPrivateTabs.cleanup") > 1
) { // SeaMonkey has some cache for fast tabs restoring and doesn't destroy closed tabs immediately
window.setTimeout(function() {
_log("Closed last private tab => forgetAllClosedTabs()");
this.forgetAllClosedTabs();
}.bind(this), 0);
if(this.isLastPrivate(tab)) {
_log("Closed last private tab");
if(this.forbidCloseLastPrivate()) {
var pos = "_tPos" in tab
? tab._tPos
: Array.indexOf(window.gBrowser.tabs, tab); // SeaMonkey
this.openNewPrivateTab(window, false, function(newTab) {
newTab && window.gBrowser.moveTabTo(newTab, pos);
});
}
else if(
this.isSeaMonkey
&& prefs.get("rememberClosedPrivateTabs.cleanup") > 1
) { // SeaMonkey has some cache for fast tabs restoring and doesn't destroy closed tabs immediately
window.setTimeout(function() {
_log("Closed last private tab => forgetAllClosedTabs()");
this.forgetAllClosedTabs();
}.bind(this), 0);
}
}
window.setTimeout(function() {
if(!this.hasPrivateTab(window)) {
_log("Closed last private tab in window");
this.clearSearchBar(window);
}
}.bind(this), 0);
}
},
cleanupClosedTab: function(e) {
Expand Down Expand Up @@ -1316,25 +1323,28 @@ var windowsObserver = {
for(var window in this.windows)
this.forgetClosedTabs(window);
},
clearSearchBar: function() {
for(var window in this.windows) {
var pt = window.privateTab;
if(pt && pt._clearSearchBarUndo) {
var searchBar = window.document.getElementById("searchbar");
if(searchBar) try {
var tb = searchBar.textbox;
if(pt._clearSearchBarValue) {
_log("Clear search bar value");
tb.value = "";
}
tb.editor.transactionManager.clear();
_log("Clear search bar undo buffer");
}
catch(e) {
Components.utils.reportError(e);
clearSearchBars: function() {
_log("clearSearchBars()");
for(var window in this.windows)
this.clearSearchBar(window);
},
clearSearchBar: function(window) {
var pt = window.privateTab;
if(pt && pt._clearSearchBarUndo) {
var searchBar = window.document.getElementById("searchbar");
if(searchBar) try {
var tb = searchBar.textbox;
if(pt._clearSearchBarValue) {
_log("Clear search bar value");
tb.value = "";
}
pt._clearSearchBarUndo = pt._clearSearchBarValue = false;
tb.editor.transactionManager.clear();
_log("Clear search bar undo buffer");
}
catch(e) {
Components.utils.reportError(e);
}
pt._clearSearchBarUndo = pt._clearSearchBarValue = false;
}
},
_hasPbExitObserver: false,
Expand Down

0 comments on commit 3002ccd

Please sign in to comment.