Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
feat(statusBar): Add an option to show/hide formatOnSave's state in t…
Browse files Browse the repository at this point in the history
…he status bar

Fixes #153
  • Loading branch information
darahak committed May 7, 2017
1 parent a4551df commit 1abded3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 30 deletions.
9 changes: 8 additions & 1 deletion dist/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
"default": true,
"order": 2
},
"showInStatusBar": {
"title": "Show in Status Bar",
"description": "Show in status bar if *Format on Save* is enabled or not.",
"type": "boolean",
"default": false,
"order": 3
},
"scopes": {
"title": "Scopes",
"description": "Use `Editor: Log Cursor Scope` to determine the scopes for a file.",
Expand All @@ -48,7 +55,7 @@
"items": {
"type": "string"
},
"order": 3
"order": 4
},
"excludedGlobs": {
"title": "Exclude (list of globs)",
Expand Down
43 changes: 30 additions & 13 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var warnAboutLinterEslintFixOnSave = null;
var displayDebugInfo = null;
var toggleFormatOnSave = null;
var subscriptions = null;
var statusBarHandler = null;
var statusBarTile = null;
var tileElement = null;

Expand Down Expand Up @@ -65,6 +66,26 @@ var lazyToggleFormatOnSave = function lazyToggleFormatOnSave() {
toggleFormatOnSave();
};

var attachStatusTile = function attachStatusTile() {
tileElement = createStatusTile();
statusBarTile = statusBarHandler.addLeftTile({
item: tileElement,
priority: 1000
});
updateStatusTile(subscriptions, tileElement);

subscriptions.add(atom.config.observe('prettier-atom.formatOnSaveOptions.enabled', function () {
return updateStatusTile(subscriptions, tileElement);
}));
};

var detachStatusTile = function detachStatusTile() {
disposeTooltip();
if (statusBarTile) {
statusBarTile.destroy();
}
};

// public API
var activate = function activate() {
subscriptions = new CompositeDisposable();
Expand All @@ -84,6 +105,9 @@ var activate = function activate() {
subscriptions.add(atom.config.observe('prettier-atom.useEslint', function () {
return lazyWarnAboutLinterEslintFixOnSave();
}));
subscriptions.add(atom.config.observe('prettier-atom.formatOnSaveOptions.showInStatusBar', function (show) {
return show ? attachStatusTile() : detachStatusTile();
}));

// HACK: an Atom bug seems to be causing old configuration settings to linger for some users
// https://github.com/jlongster/prettier-atom/issues/72
Expand All @@ -93,23 +117,16 @@ var activate = function activate() {

var deactivate = function deactivate() {
subscriptions.dispose();
disposeTooltip();
if (statusBarTile) {
statusBarTile.destroy();
}
detachStatusTile();
};

var consumeStatusBar = function consumeStatusBar(statusBar) {
tileElement = createStatusTile();
statusBarTile = statusBar.addLeftTile({
item: tileElement,
priority: 1000
});
updateStatusTile(subscriptions, tileElement);
statusBarHandler = statusBar;

subscriptions.add(atom.config.observe('prettier-atom.formatOnSaveOptions.enabled', function () {
return updateStatusTile(subscriptions, tileElement);
}));
var showInStatusBar = atom.config.get('prettier-atom.formatOnSaveOptions.showInStatusBar');
if (showInStatusBar) {
attachStatusTile();
}
};

module.exports = {
Expand Down
9 changes: 8 additions & 1 deletion src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
"default": true,
"order": 2
},
"showInStatusBar": {
"title": "Show in Status Bar",
"description": "Show in status bar if *Format on Save* is enabled or not.",
"type": "boolean",
"default": false,
"order": 3
},
"scopes": {
"title": "Scopes",
"description": "Use `Editor: Log Cursor Scope` to determine the scopes for a file.",
Expand All @@ -48,7 +55,7 @@
"items": {
"type": "string"
},
"order": 3
"order": 4
},
"excludedGlobs": {
"title": "Exclude (list of globs)",
Expand Down
50 changes: 35 additions & 15 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let warnAboutLinterEslintFixOnSave = null;
let displayDebugInfo = null;
let toggleFormatOnSave = null;
let subscriptions = null;
let statusBarHandler = null;
let statusBarTile = null;
let tileElement = null;

Expand Down Expand Up @@ -55,6 +56,28 @@ const lazyToggleFormatOnSave = () => {
toggleFormatOnSave();
};

const attachStatusTile = () => {
tileElement = createStatusTile();
statusBarTile = statusBarHandler.addLeftTile({
item: tileElement,
priority: 1000,
});
updateStatusTile(subscriptions, tileElement);

subscriptions.add(
atom.config.observe('prettier-atom.formatOnSaveOptions.enabled', () =>
updateStatusTile(subscriptions, tileElement),
),
);
};

const detachStatusTile = () => {
disposeTooltip();
if (statusBarTile) {
statusBarTile.destroy();
}
};

// public API
const activate = () => {
subscriptions = new CompositeDisposable();
Expand All @@ -76,6 +99,12 @@ const activate = () => {
subscriptions.add(
atom.config.observe('prettier-atom.useEslint', () => lazyWarnAboutLinterEslintFixOnSave()),
);
subscriptions.add(
atom.config.observe(
'prettier-atom.formatOnSaveOptions.showInStatusBar',
show => show ? attachStatusTile() : detachStatusTile(),
),
);

// HACK: an Atom bug seems to be causing old configuration settings to linger for some users
// https://github.com/jlongster/prettier-atom/issues/72
Expand All @@ -85,25 +114,16 @@ const activate = () => {

const deactivate = () => {
subscriptions.dispose();
disposeTooltip();
if (statusBarTile) {
statusBarTile.destroy();
}
detachStatusTile();
};

const consumeStatusBar = (statusBar) => {
tileElement = createStatusTile();
statusBarTile = statusBar.addLeftTile({
item: tileElement,
priority: 1000,
});
updateStatusTile(subscriptions, tileElement);
statusBarHandler = statusBar;

subscriptions.add(
atom.config.observe('prettier-atom.formatOnSaveOptions.enabled', () =>
updateStatusTile(subscriptions, tileElement),
),
);
const showInStatusBar = atom.config.get('prettier-atom.formatOnSaveOptions.showInStatusBar');
if (showInStatusBar) {
attachStatusTile();
}
};

module.exports = {
Expand Down

0 comments on commit 1abded3

Please sign in to comment.