@@ -175,9 +175,14 @@ export default class GithubPackage {
175
175
return ! ! event . target . closest ( '.github-FilePatchListView' ) . querySelector ( '.is-selected' ) ;
176
176
} ;
177
177
178
+ const handleProjectPathsChange = ( ) => {
179
+ const activeRepository = this . getActiveRepository ( ) ;
180
+ const activeRepositoryPath = activeRepository ? activeRepository . getWorkingDirectoryPath ( ) : null ;
181
+ this . scheduleActiveContextUpdate ( { activeRepositoryPath} ) ;
182
+ } ;
183
+
178
184
this . subscriptions . add (
179
- this . project . onDidChangePaths ( this . scheduleActiveContextUpdate ) ,
180
- this . workspace . getCenter ( ) . onDidChangeActivePaneItem ( this . scheduleActiveContextUpdate ) ,
185
+ this . project . onDidChangePaths ( handleProjectPathsChange ) ,
181
186
this . styleCalculator . startWatching (
182
187
'github-package-styles' ,
183
188
[ 'editor.fontSize' , 'editor.fontFamily' , 'editor.lineHeight' , 'editor.tabLength' ] ,
@@ -269,6 +274,10 @@ export default class GithubPackage {
269
274
} ) ) ;
270
275
}
271
276
277
+ const changeWorkingDirectory = workingDirectory => {
278
+ this . scheduleActiveContextUpdate ( { activeRepositoryPath : workingDirectory } ) ;
279
+ } ;
280
+
272
281
this . renderFn (
273
282
< RootController
274
283
ref = { c => { this . controller = c ; } }
@@ -294,6 +303,8 @@ export default class GithubPackage {
294
303
startOpen = { this . startOpen }
295
304
startRevealed = { this . startRevealed }
296
305
removeFilePatchItem = { this . removeFilePatchItem }
306
+ currentWorkDir = { this . getActiveWorkdir ( ) }
307
+ changeWorkingDirectory = { changeWorkingDirectory }
297
308
/> , this . element , callback ,
298
309
) ;
299
310
}
@@ -495,14 +506,13 @@ export default class GithubPackage {
495
506
* Derive the git working directory context that should be used for the package's git operations based on the current
496
507
* state of the Atom workspace. In priority, this prefers:
497
508
*
498
- * - A git working directory that contains the active pane item in the workspace's center.
499
- * - A git working directory corresponding to a single Project.
500
- * - When initially activating the package, the working directory that was active when the package was last
501
- * serialized.
509
+ * - The preferred git working directory set by the user (This is also the working directory that was active when the
510
+ * package was last serialized).
511
+ * - A git working directory corresponding to "first" Project, whether or not there is a single project or multiple.
502
512
* - The current context, unchanged, which may be a `NullWorkdirContext`.
503
513
*
504
514
* First updates the pool of resident contexts to match all git working directories that correspond to open
505
- * projects and pane items .
515
+ * projects.
506
516
*/
507
517
async getNextContext ( savedState ) {
508
518
const workdirs = new Set (
@@ -514,50 +524,34 @@ export default class GithubPackage {
514
524
) ,
515
525
) ;
516
526
517
- const fromPaneItem = async maybeItem => {
518
- const itemPath = pathForPaneItem ( maybeItem ) ;
519
-
520
- if ( ! itemPath ) {
521
- return { } ;
522
- }
523
-
524
- const itemWorkdir = await this . workdirCache . find ( itemPath ) ;
525
-
526
- if ( itemWorkdir && ! this . project . contains ( itemPath ) ) {
527
- workdirs . add ( itemWorkdir ) ;
528
- }
529
-
530
- return { itemPath, itemWorkdir} ;
531
- } ;
532
-
533
- const active = await fromPaneItem ( this . workspace . getCenter ( ) . getActivePaneItem ( ) ) ;
534
-
527
+ // Update pool with the open projects
535
528
this . contextPool . set ( workdirs , savedState ) ;
536
529
537
- if ( active . itemPath ) {
538
- // Prefer an active item
539
- return this . contextPool . getContext ( active . itemWorkdir || active . itemPath ) ;
530
+ if ( savedState . activeRepositoryPath ) {
531
+ // Preferred git directory (the preferred directory or the last serialized directory).
532
+ const stateContext = this . contextPool . getContext ( savedState . activeRepositoryPath ) ;
533
+ // If the context exists chose it, else continue.
534
+ if ( stateContext . isPresent ( ) ) {
535
+ return stateContext ;
536
+ }
540
537
}
541
538
542
- if ( this . project . getPaths ( ) . length === 1 ) {
543
- // Single project
544
- const projectPath = this . project . getPaths ( ) [ 0 ] ;
539
+ const projectPaths = this . project . getPaths ( ) ;
540
+
541
+ if ( projectPaths . length >= 1 ) {
542
+ // Single or multiple projects (just choose the first, the user can select after)
543
+ const projectPath = projectPaths [ 0 ] ;
545
544
const activeWorkingDir = await this . workdirCache . find ( projectPath ) ;
546
545
return this . contextPool . getContext ( activeWorkingDir || projectPath ) ;
547
546
}
548
547
549
- if ( this . project . getPaths ( ) . length === 0 && ! this . activeContext . getRepository ( ) . isUndetermined ( ) ) {
548
+ if ( projectPaths . length === 0 && ! this . activeContext . getRepository ( ) . isUndetermined ( ) ) {
550
549
// No projects. Revert to the absent context unless we've guessed that more projects are on the way.
551
550
return WorkdirContext . absent ( { pipelineManager : this . pipelineManager } ) ;
552
551
}
553
552
554
- // Restore models from saved state. Will return a NullWorkdirContext if this path is not presently
555
- // resident in the pool.
556
- const savedWorkingDir = savedState . activeRepositoryPath ;
557
- if ( savedWorkingDir ) {
558
- return this . contextPool . getContext ( savedWorkingDir ) ;
559
- }
560
-
553
+ // It is only possible to reach here if there there was no preferred directory, there are no project paths and the
554
+ // the active context's repository is not undetermined.
561
555
return this . activeContext ;
562
556
}
563
557
@@ -600,22 +594,3 @@ export default class GithubPackage {
600
594
}
601
595
}
602
596
}
603
-
604
- function pathForPaneItem ( paneItem ) {
605
- if ( ! paneItem ) {
606
- return null ;
607
- }
608
-
609
- // Likely GitHub package provided pane item
610
- if ( typeof paneItem . getWorkingDirectory === 'function' ) {
611
- return paneItem . getWorkingDirectory ( ) ;
612
- }
613
-
614
- // TextEditor-like
615
- if ( typeof paneItem . getPath === 'function' ) {
616
- return paneItem . getPath ( ) ;
617
- }
618
-
619
- // Oh well
620
- return null ;
621
- }
0 commit comments