always close empty tree-view

This commit is contained in:
DrMaxNix 2023-08-24 12:11:33 +02:00
parent 8eb94fbf08
commit 10a85d570b
3 changed files with 45 additions and 32 deletions

View File

@ -13,7 +13,7 @@ Open your init script:
When the file is called `init.js`, add this snippet to the file:
```js
// RESET FLAG //
// RESET //
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;
@ -27,12 +27,9 @@ atom.workspace.onDidOpen(function({item}){
// remember that the code ran once
codeRanOnce = true;
// check whether the `Hidden On Startup` setting is activated
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || false){
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
}
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
});
@ -51,8 +48,13 @@ tryTreeViewClose = function(){
// check if tree-view element exists
if(!treeView) return;
// close the tree-view dock
treeView.hide();
// check whether tree view contains projects
var treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null);
// close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || !treeViewHasProjects){
treeView.hide();
}
// stop trying
clearInterval(tryTreeViewCloseInterval);
@ -75,11 +77,10 @@ atom.workspace.onDidOpen ({item}) ->
# remember that the code ran once
codeRanOnce = true
# check whether the `Hidden On Startup` setting is activated
if atom.packages.config.settings["tree-view"].hiddenOnStartup || false
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
## TRY TO CLOSE THE TREE-VIEW ##
@ -96,8 +97,12 @@ tryTreeViewClose = () ->
# check if tree-view element exists
if !treeView then return;
# close the tree-view dock
treeView.hide()
# check whether tree view contains projects
treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null)
# close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
if atom.packages.config.settings["tree-view"].hiddenOnStartup || !treeViewHasProjects
treeView.hide()
# stop trying
clearInterval(tryTreeViewCloseInterval)
@ -107,4 +112,8 @@ Now you can configure whether you want the tree-view to be hidden on startup in
`Edit > Preferences > Packages > tree-view > Hidden On Startup`
**Hidden On Startup: checked**: Always hide the tree-view on startup
**Hidden On Startup: not checked**: Only hide tree-view on startup when it does not contain open projects
> Successfully tested using Pulsar v1.104.0

View File

@ -12,11 +12,9 @@ atom.workspace.onDidOpen ({item}) ->
# remember that the code ran once
codeRanOnce = true
# check whether the `Hidden On Startup` setting is activated
if atom.packages.config.settings["tree-view"].hiddenOnStartup || false
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
## TRY TO CLOSE THE TREE-VIEW ##
@ -33,8 +31,12 @@ tryTreeViewClose = () ->
# check if tree-view element exists
if !treeView then return;
# close the tree-view dock
treeView.hide()
# check whether tree view contains projects
treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null)
# close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
if atom.packages.config.settings["tree-view"].hiddenOnStartup || !treeViewHasProjects
treeView.hide()
# stop trying
clearInterval(tryTreeViewCloseInterval)

View File

@ -1,4 +1,4 @@
// RESET FLAG //
// RESET //
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;
@ -12,12 +12,9 @@ atom.workspace.onDidOpen(function({item}){
// remember that the code ran once
codeRanOnce = true;
// check whether the `Hidden On Startup` setting is activated
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || false){
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
}
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
});
@ -36,8 +33,13 @@ tryTreeViewClose = function(){
// check if tree-view element exists
if(!treeView) return;
// close the tree-view dock
treeView.hide();
// check whether tree view contains projects
var treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null);
// close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
if(atom.packages.config.settings["tree-view"].hiddenOnStartup || !treeViewHasProjects){
treeView.hide();
}
// stop trying
clearInterval(tryTreeViewCloseInterval);