Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit faecb7c

Browse files
authored
Merge pull request #129 from UziTech/persistent-project-bar
Persistent project bar
2 parents 6f016ae + 2531924 commit faecb7c

File tree

7 files changed

+147
-18
lines changed

7 files changed

+147
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [next](https://github.com/cakecatz/flex-toolbar/compare/v0.14.0...master)
22
- Add project config path setting [#128](https://github.com/cakecatz/flex-toolbar/pull/128) (by [@malnvenshorn](https://github.com/malnvenshorn))
3+
- Add persistent project tool bar setting [#129](https://github.com/cakecatz/flex-toolbar/pull/129) (by [@UziTech](https://github.com/UziTech))
34

45
## [v0.14.0](https://github.com/cakecatz/flex-toolbar/compare/v0.13.2...v0.14.0) - 2018-01-17
56
- Add package conditions [#126](https://github.com/cakecatz/flex-toolbar/pull/126) (by [@UziTech](https://github.com/UziTech))

lib/flex-tool-bar.coffee

+18-11
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ module.exports =
1414
watchList: []
1515

1616
config:
17+
persistentProjectToolBar:
18+
description: 'Project tool bar will stay when focus is moved away from a project file'
19+
type: 'boolean'
20+
default: false
21+
reloadToolBarNotification:
22+
type: 'boolean'
23+
default: true
24+
reloadToolBarWhenEditConfigFile:
25+
type: 'boolean'
26+
default: true
1727
toolBarConfigurationFilePath:
1828
type: 'string'
1929
default: atom.getConfigDirPath()
2030
toolBarProjectConfigurationFilePath:
2131
type: 'string'
2232
default: '.'
23-
reloadToolBarWhenEditConfigFile:
24-
type: 'boolean'
25-
default: true
26-
reloadToolBarNotification:
27-
type: 'boolean'
28-
default: true
2933
useBrowserPlusWhenItIsActive:
3034
type: 'boolean'
3135
default: false
@@ -101,7 +105,8 @@ module.exports =
101105
return false
102106

103107
resolveProjectConfigPath: ->
104-
@projectToolbarConfigPath = null
108+
persistent = atom.config.get 'flex-tool-bar.persistentProjectToolBar'
109+
@projectToolbarConfigPath = null unless persistent
105110
relativeProjectConfigPath = atom.config.get 'flex-tool-bar.toolBarProjectConfigurationFilePath'
106111
editor = atom.workspace.getActivePaneItem()
107112
file = editor?.buffer?.file or editor?.file
@@ -113,7 +118,8 @@ module.exports =
113118
if fs.isFileSync(pathToCheck)
114119
@projectToolbarConfigPath = pathToCheck
115120
else
116-
@projectToolbarConfigPath = fs.resolve pathToCheck, 'toolbar', ['cson', 'json5', 'json', 'js', 'coffee']
121+
found = fs.resolve pathToCheck, 'toolbar', ['cson', 'json5', 'json', 'js', 'coffee']
122+
@projectToolbarConfigPath = found if found
117123

118124
if @projectToolbarConfigPath is @configFilePath
119125
@projectToolbarConfigPath = null
@@ -190,10 +196,10 @@ module.exports =
190196
throw error
191197

192198
fixToolBarHeight: ->
193-
@getToolbarView().element.style.height = "#{@getToolbarView().element.offsetHeight}px"
199+
@getToolbarView()?.element?.style.height = "#{@getToolbarView().element.offsetHeight}px"
194200

195201
unfixToolBarHeight: ->
196-
@getToolbarView().element.style.height = null
202+
@getToolbarView()?.element?.style.height = null
197203

198204
addButtons: (toolBarButtons) ->
199205
if toolBarButtons?
@@ -363,7 +369,7 @@ module.exports =
363369
return false
364370

365371
removeButtons: ->
366-
@toolBar.removeItems() if @toolBar?
372+
@toolBar?.removeItems()
367373

368374
deactivate: ->
369375
@watcherList.forEach (watcher) ->
@@ -372,5 +378,6 @@ module.exports =
372378
@subscriptions.dispose()
373379
@subscriptions = null
374380
@removeButtons()
381+
@toolBar = null
375382

376383
serialize: ->

spec/fixtures/project1/sample.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* eslint-disable */
2+
undefined

spec/fixtures/project1/toolbar.cson

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
type: "button"
4+
icon: "octoface"
5+
callback: "application:about"
6+
tooltip: "project1"
7+
}
8+
]

spec/fixtures/project2/sample.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* eslint-disable */
2+
undefined

spec/flex-tool-bar-spec.js

+78-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ describe('FlexToolBar', function () {
66
await atom.packages.activatePackage('tool-bar');
77
await atom.packages.activatePackage('flex-tool-bar');
88
});
9+
afterEach(async function () {
10+
await atom.reset();
11+
});
912

1013
describe('activate', function () {
1114
it('should store grammar', async function () {
@@ -180,29 +183,97 @@ describe('FlexToolBar', function () {
180183
});
181184

182185
describe('correct project config path', function () {
183-
beforeAll(function () {
186+
beforeEach(function () {
184187
flexToolBar.configFilePath = path.resolve(__dirname, './fixtures/config/config.json');
185188
});
186189

187-
it('should load toolbar.cson from specified path', function () {
190+
it('should load toolbar.cson from specified path', async function () {
188191
atom.config.set('flex-tool-bar.toolBarProjectConfigurationFilePath', '.');
189-
flexToolBar.resolveProjectConfigPath();
192+
await atom.workspace.open(path.join(__dirname, 'fixtures/sample.js'));
190193
expect(flexToolBar.projectToolbarConfigPath).toBe(path.resolve(__dirname, './fixtures/toolbar.cson'));
191194
});
192195

193-
it('should load specified config file', function () {
196+
it('should load specified config file', async function () {
194197
atom.config.set('flex-tool-bar.toolBarProjectConfigurationFilePath', './config/config.cson');
195-
flexToolBar.resolveProjectConfigPath();
198+
await atom.workspace.open(path.join(__dirname, 'fixtures/sample.js'));
196199
expect(flexToolBar.projectToolbarConfigPath).toBe(path.resolve(__dirname, './fixtures/config/config.cson'));
197200
});
198201

199-
it('should not load if path equals global config file', function () {
202+
it('should not load if path equals global config file', async function () {
200203
atom.config.set('flex-tool-bar.toolBarProjectConfigurationFilePath', './config/config.json');
201-
flexToolBar.resolveProjectConfigPath();
204+
await atom.workspace.open(path.join(__dirname, 'fixtures/sample.js'));
202205
expect(flexToolBar.projectToolbarConfigPath).toBe(null);
203206
});
204207
});
205208

209+
describe('persistent project tool bar', function () {
210+
beforeEach(async function () {
211+
this.project1Config = path.join(__dirname, 'fixtures/project1/toolbar.cson');
212+
this.project2Config = path.join(__dirname, 'fixtures/project2/toolbar.cson');
213+
this.project1Sample = path.join(__dirname, 'fixtures/project1/sample.js');
214+
this.project2Sample = path.join(__dirname, 'fixtures/project2/sample.js');
215+
this.project3Sample = path.join(__dirname, 'fixtures/project3/sample.js');
216+
this.settingsView = 'atom://config/packages/flex-toolbar';
217+
218+
await atom.packages.activatePackage('settings-view');
219+
flexToolBar.projectToolbarConfigPath = null;
220+
atom.project.setPaths([
221+
path.join(__dirname, 'fixtures/project1/'),
222+
path.join(__dirname, 'fixtures/project2/'),
223+
path.join(__dirname, 'fixtures/project3/'),
224+
]);
225+
});
226+
it('should not persistent when an editor is open that does not have a project config', async function () {
227+
atom.config.set('flex-tool-bar.persistentProjectToolBar', false);
228+
229+
await atom.workspace.open(this.project1Sample);
230+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
231+
232+
await atom.workspace.open(this.settingsView);
233+
expect(flexToolBar.projectToolbarConfigPath).toBeNull();
234+
235+
await atom.workspace.open(this.project3Sample);
236+
expect(flexToolBar.projectToolbarConfigPath).toBeNull();
237+
238+
await atom.workspace.open(this.project2Sample);
239+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project2Config);
240+
241+
await atom.workspace.open(this.settingsView);
242+
expect(flexToolBar.projectToolbarConfigPath).toBeNull();
243+
244+
await atom.workspace.open(this.project3Sample);
245+
expect(flexToolBar.projectToolbarConfigPath).toBeNull();
246+
247+
await atom.workspace.open(this.project1Sample);
248+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
249+
});
250+
251+
it('should persistent when an editor is open that does not have a project config', async function () {
252+
atom.config.set('flex-tool-bar.persistentProjectToolBar', true);
253+
254+
await atom.workspace.open(this.project1Sample);
255+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
256+
257+
await atom.workspace.open(this.settingsView);
258+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
259+
260+
await atom.workspace.open(this.project3Sample);
261+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
262+
263+
await atom.workspace.open(this.project2Sample);
264+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project2Config);
265+
266+
await atom.workspace.open(this.settingsView);
267+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project2Config);
268+
269+
await atom.workspace.open(this.project3Sample);
270+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project2Config);
271+
272+
await atom.workspace.open(this.project1Sample);
273+
expect(flexToolBar.projectToolbarConfigPath).toBe(this.project1Config);
274+
});
275+
});
276+
206277
if (!global.headless) {
207278
// show linting errors in atom test window
208279
describe('linting', function () {

toolbar.cson

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
type: "url"
4+
icon: "octoface"
5+
url: "http://github.com"
6+
tooltip: "Github Page"
7+
}
8+
{
9+
type: "spacer"
10+
}
11+
{
12+
type: "button"
13+
icon: "document"
14+
callback: "application:new-file"
15+
tooltip: "New File"
16+
iconset: "ion"
17+
mode: "dev"
18+
}
19+
{
20+
type: "button"
21+
icon: "columns"
22+
iconset: "fa"
23+
callback: ["pane:split-right", "pane:split-right"]
24+
}
25+
{
26+
type: "button"
27+
icon: "circuit-board"
28+
callback: "git-diff:toggle-diff-list"
29+
style:
30+
color: "#FA4F28"
31+
}
32+
{
33+
type: "button"
34+
icon: "markdown"
35+
callback: "markdown-preview:toggle"
36+
disable: "!markdown"
37+
}
38+
]

0 commit comments

Comments
 (0)