@@ -8,12 +8,7 @@ import StatusView from './views/StatusView';
88import Config from './Config' ;
99import Runner from './Runner' ;
1010
11- export default {
12- statusBarTile : null ,
13- statusView : null ,
14- subscriptions : null ,
15- config : null ,
16- runner : null ,
11+ class AtomHooks {
1712
1813 activate ( ) {
1914 this . subscriptions = new CompositeDisposable ( ) ;
@@ -32,7 +27,12 @@ export default {
3227
3328 this . readConfig ( ) ;
3429
35- this . subscriptions . add ( atom . commands . add ( 'atom-text-editor' , 'atom-hooks:show' , ( ) => this . onToggleHooksList ( ) ) ) ;
30+ // this handler for modal hooks list
31+ this . subscriptions . add ( atom . commands . add ( 'atom-workspace' , 'atom-hooks:show' , event => {
32+ const filePath = event . target . getAttribute ( 'data-path' ) ;
33+
34+ this . onToggleHooksList ( filePath ) ;
35+ } ) ) ;
3636
3737 // reload our config when it is modified
3838 this . subscriptions . add ( atom . config . observe ( 'atom-hooks' , ( ) => this . readConfig ( ) ) ) ;
@@ -42,24 +42,24 @@ export default {
4242
4343 // onSave hook
4444 this . subscriptions . add ( atom . workspace . observeTextEditors ( textEditor => this . subscriptions . add ( textEditor . onDidSave ( event => this . onSaveFile ( event . path ) ) ) ) ) ;
45- } ,
45+ }
4646
4747 readConfig ( ) {
4848 this . config . setConfig ( {
4949 scripts : atom . config . get ( 'atom-hooks.scripts' ) || { } ,
5050 hooks : atom . config . get ( 'atom-hooks.hooks' ) || { }
5151 } ) ;
52- } ,
52+ }
5353
5454 getCurrentFile ( ) {
55- const paneItem = atom . workspace . getActivePaneItem ( ) ;
55+ const paneItem = atom . workspace . getCenter ( ) . getActivePaneItem ( ) ;
5656
5757 if ( paneItem && paneItem . getPath ) {
5858 return paneItem . getPath ( ) ;
5959 }
6060
6161 return null ;
62- } ,
62+ }
6363
6464 consumeStatusBar ( statusBar ) {
6565 this . statusBarTile = statusBar . addRightTile ( {
@@ -68,30 +68,35 @@ export default {
6868 } ) ;
6969
7070 this . statusView . hide ( ) ; // do not show till the text editor will be active
71- } ,
71+ }
7272
7373 onChangeActivePane ( ) {
74- if ( this . getCurrentFile ( ) && this . config . listHooks ( this . getCurrentFile ( ) ) . length ) {
74+ const filePath = this . getCurrentFile ( ) ;
75+
76+ if ( filePath && this . config . listHooks ( filePath ) . length ) {
7577 this . statusView . show ( ) ;
7678 } else {
7779 this . statusView . hide ( ) ;
7880 }
79- } ,
81+ }
8082
81- onToggleHooksList ( ) {
83+ onToggleHooksList ( filePath ) {
8284 if ( ! this . hooksListView ) {
8385 this . hooksListView = new HooksListView ( {
84- listHooks : ( ) => this . config . listHooks ( this . getCurrentFile ( ) ) ,
85- runCommand : command => this . processExecutionResult ( this . runner . runCommand ( this . getCurrentFile ( ) , command ) )
86+ runCommand : ( filePath , command ) => this . processExecutionResult ( this . runner . runCommand ( filePath , command ) )
8687 } ) ;
8788 }
8889
89- this . hooksListView . toggle ( ) ;
90- } ,
90+ filePath = filePath || this . getCurrentFile ( ) ;
91+
92+ if ( filePath ) {
93+ this . hooksListView . show ( filePath , this . config . listHooks ( filePath ) ) ;
94+ }
95+ }
9196
9297 onSaveFile ( filePath ) {
93- this . processExecutionResult ( this . runner . run ( filePath , 'onSave' ) ) ;
94- } ,
98+ this . processExecutionResult ( this . runner . runHook ( filePath , 'onSave' ) ) ;
99+ }
95100
96101 processExecutionResult ( result ) {
97102 this . statusView . updateState ( 'loading' ) ;
@@ -100,14 +105,14 @@ export default {
100105 this . statusView . updateState ( 'fail' ) ;
101106 this . notifyError ( 'Error executing onSave scripts' , error ) ;
102107 } ) ;
103- } ,
108+ }
104109
105110 notifyError ( message , detail ) {
106111 atom . notifications . addError ( message , {
107112 detail : typeof detail === 'object' ? _JSON$stringify ( detail , null , 2 ) : detail ,
108113 dismissable : true
109114 } ) ;
110- } ,
115+ }
111116
112117 deactivate ( ) {
113118 this . subscriptions . dispose ( ) ;
@@ -120,9 +125,15 @@ export default {
120125
121126 this . subscriptions = null ;
122127 this . statusBarTile = null ;
128+ // $FlowFixMe
123129 this . hooksListView = null ;
130+ // $FlowFixMe
124131 this . statusView = null ;
132+ // $FlowFixMe
125133 this . config = null ;
134+ // $FlowFixMe
126135 this . runner = null ;
127136 }
128- } ;
137+ }
138+
139+ export default new AtomHooks ( ) ;
0 commit comments