pulsar-tame-tree-view/README.md

123 lines
3.8 KiB
Markdown
Raw Permalink Normal View History

2023-05-11 20:24:05 +02:00
# Tame Pulsar Tree View
Tame your Pulsar (Atom) editor's tree view by making it obey the "Hidden On Startup" setting!
### Why?
2023-05-11 20:39:00 +02:00
It is a well-known bug that Atom, and its fork Pulsar, don't properly respect the `Hidden On Startup` setting of its tree view.
2023-05-11 20:24:05 +02:00
I have used a lot of bodge-fixes for this in the past, but every now and then they stopped working due to updates. With this repository I'm trying to maintain a working code snippet for Pulsar's `init.coffee` which will make the `Hidden On Startup` setting work the way it should.
### Setup Instructions
Open your init script:
`Edit > Init Script`
When the file is called `init.js`, add this snippet to the file:
```js
// RESET //
2023-05-11 20:24:05 +02:00
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;
2023-05-11 20:24:05 +02:00
// EXECUTE CODE WHEN WORKSPACE IS OPENED //
atom.workspace.onDidOpen(function({item}){
// make sure the code doesn't run twice
if(codeRanOnce) return;
// remember that the code ran once
codeRanOnce = true;
// schedule multiple tries to close the tree-view
tryTreeViewClose();
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
2023-05-11 20:24:05 +02:00
});
// TRY TO CLOSE THE TREE-VIEW //
tryTreeViewClose = function(){
// get tree-view element
var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
// time out after too many tries
tryTreeViewCloseIntervalCount++;
if(tryTreeViewCloseIntervalCount >= 20){
clearInterval(tryTreeViewCloseInterval);
return;
}
// check if tree-view element exists
if(!treeView) return;
// 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
let treeViewSettings = atom.packages.config.settings["tree-view"] ?? {};
let hiddenOnStartup = treeViewSettings.hiddenOnStartup ?? false;
if(hiddenOnStartup || !treeViewHasProjects){
treeView.hide();
}
// stop trying
clearInterval(tryTreeViewCloseInterval);
}
2023-05-11 20:24:05 +02:00
```
When the file is called `init.coffee`, add this snippet to the file:
```coffee
## RESET ##
2023-05-11 20:24:05 +02:00
codeRanOnce = false
tryTreeViewCloseInterval = null
tryTreeViewCloseIntervalCount = 0
2023-05-11 20:24:05 +02:00
## EXECUTE CODE WHEN WORKSPACE IS OPENED ##
2023-05-15 13:32:49 +02:00
atom.workspace.onDidOpen ({item}) ->
2023-05-11 20:24:05 +02:00
# make sure the code doesn't run twice
if codeRanOnce then return
# remember that the code ran once
codeRanOnce = true
# schedule multiple tries to close the tree-view
tryTreeViewClose()
tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)
## TRY TO CLOSE THE TREE-VIEW ##
tryTreeViewClose = () ->
# get tree-view element
treeView = atom.workspace.paneContainerForURI("atom://tree-view")
# time out after too many tries
tryTreeViewCloseIntervalCount++
if tryTreeViewCloseIntervalCount >= 20
clearInterval(tryTreeViewCloseInterval)
return;
# check if tree-view element exists
if !treeView then return;
# 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
treeViewSettings = atom.packages.config.settings["tree-view"] ? {}
hiddenOnStartup = treeViewSettings.hiddenOnStartup ? false
if hiddenOnStartup || !treeViewHasProjects
treeView.hide()
# stop trying
clearInterval(tryTreeViewCloseInterval)
2023-05-11 20:24:05 +02:00
```
Now you can configure whether you want the tree-view to be hidden on startup in the settings of the `tree-view` package:
`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.114.0