@@ -101,7 +101,7 @@ export default {
101
101
: enableNotif ? atom . notifications . addSuccess ( `New import added!` ) : 0 ;
102
102
} ,
103
103
104
- popNotif ( relativePath , editor ) {
104
+ insertStatement ( relativePath , editor ) {
105
105
106
106
const _path = editor . getPath ( ) . toString ( ) ;
107
107
const extname = path . extname ( _path ) ;
@@ -135,53 +135,49 @@ export default {
135
135
: this . toImportPositionTop ( importText , editor , importName ) ;
136
136
} ,
137
137
138
- warnNotif ( options , fromFileType , toFileType ) {
139
-
140
- const { isSameValid, notSupportedValid, invalidFileTrue } = options ;
138
+ notify ( options , fromExtname , toExtname ) {
139
+ const { isSameValid, notSupportedValid, invalidFile, isDirectory } = options ;
141
140
const notif = atom . notifications ;
142
- const append = fromFileType . toUpperCase ( ) . substring ( 1 ) ;
143
-
144
- invalidFileTrue ? notif . addWarning ( `Unable to import ${ fromFileType } to ${ toFileType } .` )
145
- : ! invalidFileTrue && isSameValid ? notif . addInfo ( 'Same file path.' )
146
- : ! invalidFileTrue && notSupportedValid ? notif . addWarning ( `${ append } files not supported.` )
147
- : ! invalidFileTrue && ! isSameValid && notSupportedValid === 0 ? notif . addWarning ( `Same file path. ${ append } files not supported.` )
148
- : ! invalidFileTrue && ! notSupportedValid && isSameValid === 0 ? notif . addError ( 'Import failed.' ) : 0 ;
141
+ const append = fromExtname . toUpperCase ( ) . substring ( 1 ) ;
142
+
143
+ invalidFile ? notif . addWarning ( `Unable to import ${ fromExtname } to ${ toExtname } .` )
144
+ : isDirectory && toExtname !== '' ? notif . addError ( 'File not found.' )
145
+ : fromExtname === '' && toExtname === '' ? notif . addError ( 'Active pane not found.' )
146
+ : ! invalidFile && isSameValid ? notif . addInfo ( 'Same file path.' )
147
+ : ! invalidFile && notSupportedValid ? notif . addWarning ( `${ append } files not supported.` )
148
+ : ! invalidFile && ! isSameValid && notSupportedValid === 0 ? notif . addWarning ( `Same file path. ${ append } files not supported.` )
149
+ : ! invalidFile && ! notSupportedValid && isSameValid === 0 ? notif . addError ( 'Import failed.' ) : 0 ;
149
150
} ,
150
151
151
- calculatePath ( editor ) {
152
-
153
- if ( editor . getPath ( ) === undefined ) return ;
152
+ setup ( item , activePane ) {
154
153
155
154
const enableNotif = ! this . param . disableNotifs ;
156
- const selectedSpan = atom . document . querySelector ( '.file.entry.list-item.selected > span' ) ;
157
- if ( ! selectedSpan )
158
- if ( enableNotif ) return atom . notifications . addError ( 'File not found.' ) ;
159
-
160
- const activePane = atom . workspace . getActiveTextEditor ( ) ;
155
+ const isFile = item . target . hasOwnProperty ( 'file' ) ;
156
+ const isDirectory = item . target . hasOwnProperty ( 'directory' ) ;
161
157
const validFileTypes = [ '.ts' , '.tsx' ] ;
162
- const fromPath = selectedSpan . dataset . path . toString ( ) ;
158
+ const fromPath = isFile ? item . target . file . path : '' ;
163
159
const toPath = activePane . getPath ( ) . toString ( ) ;
164
160
const relativePath = relative ( toPath , fromPath ) ;
165
- const fromFileType = path . extname ( fromPath ) ;
166
- const toFileType = path . extname ( toPath ) ;
167
- const from_valid = validFileTypes . some ( el => fromFileType . includes ( el ) ) ;
168
- const to_valid = validFileTypes . some ( el => toFileType . includes ( el ) ) ;
161
+ const fromExtname = path . extname ( fromPath ) ;
162
+ const toExtname = path . extname ( toPath ) ;
163
+ const fromIsValid = validFileTypes . some ( el => fromExtname . includes ( el ) ) ;
164
+ const toIsValid = validFileTypes . some ( el => toExtname . includes ( el ) ) ;
169
165
const isSamePath = ( fromPath === toPath ) ;
170
- const isBothValid = ( from_valid && to_valid ) ;
171
- const isSameType = ( fromFileType === toFileType ) ;
166
+ const isBothValid = ( fromIsValid && toIsValid ) ;
167
+ const isSameType = ( fromExtname === toExtname ) ;
172
168
173
169
if ( isSamePath && isBothValid && isSameType && enableNotif )
174
- this . warnNotif ( { invalidFileTrue : false , isSameValid : true , notSupportedValid : 0 } , fromFileType , toFileType ) ;
170
+ this . notify ( { invalidFile : false , isSameValid : true , notSupportedValid : 0 , isDirectory } , fromExtname , toExtname ) ;
175
171
else if ( ! isSamePath && ! isBothValid && isSameType && enableNotif )
176
- this . warnNotif ( { invalidFileTrue : false , isSameValid : 0 , notSupportedValid : true } , fromFileType , toFileType ) ;
172
+ this . notify ( { invalidFile : false , isSameValid : 0 , notSupportedValid : true , isDirectory } , fromExtname , toExtname ) ;
177
173
else if ( isSamePath && ! isBothValid && isSameType && enableNotif )
178
- this . warnNotif ( { invalidFileTrue : false , isSameValid : false , notSupportedValid : 0 } , fromFileType , toFileType ) ;
174
+ this . notify ( { invalidFile : false , isSameValid : false , notSupportedValid : 0 , isDirectory } , fromExtname , toExtname ) ;
179
175
else if ( ! isSamePath && ! isBothValid && ! isSameType && enableNotif )
180
- this . warnNotif ( { invalidFileTrue : false , isSameValid : 0 , notSupportedValid : false } , fromFileType , toFileType ) ;
176
+ this . notify ( { invalidFile : false , isSameValid : 0 , notSupportedValid : false , isDirectory } , fromExtname , toExtname ) ;
181
177
else if ( ! isSamePath && isBothValid && ! isSameType && enableNotif )
182
- this . warnNotif ( { invalidFileTrue : true , isSameValid : 0 , notSupportedValid : 0 } , fromFileType , toFileType ) ;
178
+ this . notify ( { invalidFile : true , isSameValid : 0 , notSupportedValid : 0 , isDirectory } , fromExtname , toExtname ) ;
183
179
else if ( ! isSamePath && isBothValid && isSameType )
184
- this . popNotif ( relativePath , editor )
180
+ this . insertStatement ( relativePath , activePane )
185
181
} ,
186
182
187
183
activate ( state ) {
@@ -194,17 +190,18 @@ export default {
194
190
const editorView = atom . views . getView ( editor ) ;
195
191
const lines = editorView . querySelector ( '.lines' ) ;
196
192
const leftDock = atom . workspace . paneContainers . left . refs . wrapperElement ;
197
- const directories = atom . document . querySelector ( '[class*="tree-view-root"]' ) ;
198
193
199
- let valid = false ; ;
200
- lines . addEventListener ( "dragenter" , ( ) => ( valid = true ) , false ) ;
201
- directories . addEventListener ( "dragleave" , ( ) => ( valid = false ) , false ) ;
194
+ let valid = false ;
195
+ lines . addEventListener ( "dragenter" , ( ) => ( valid = true ) , false ) ;
196
+ leftDock . addEventListener ( "dragenter" , ( e ) => e . target . ondragenter = ( ) => ( valid = false ) , false ) ;
202
197
203
198
this . subscriptions . add ( lines , "drop" , ( _lines ) => {
204
199
_lines . preventDefault ( ) ;
205
200
206
- leftDock . ondragend = ( _leftDock ) => {
207
- valid ? this . calculatePath ( editor ) : 0 ;
201
+ leftDock . ondragend = ( item ) => {
202
+ const activePane = atom . workspace . getActiveTextEditor ( ) ;
203
+
204
+ valid && activePane ? this . setup ( item , activePane ) : this . notify ( { } , '' , '' ) ;
208
205
}
209
206
} ) ;
210
207
0 commit comments