3
3
4
4
import {
5
5
commands , ConfigurationChangeEvent , ExtensionContext ,
6
- workspace , WorkspaceConfiguration ,
6
+ workspace ,
7
7
} from "vscode" ;
8
8
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
9
9
import { Commands } from "./commands" ;
10
10
import { syncHandler } from "./syncHandler" ;
11
+ import { contextManager , DependencyExplorer } from "../extension.bundle" ;
11
12
12
13
export class Settings {
13
14
14
15
public static initialize ( context : ExtensionContext ) : void {
15
16
context . subscriptions . push ( workspace . onDidChangeConfiguration ( ( e : ConfigurationChangeEvent ) => {
16
- if ( ! e . affectsConfiguration ( "java.dependency" ) ) {
17
- return ;
18
- }
19
- const oldConfig = this . _dependencyConfig ;
20
- this . _dependencyConfig = workspace . getConfiguration ( "java.dependency" ) ;
21
- for ( const listener of this . _configurationListeners ) {
22
- listener ( this . _dependencyConfig , oldConfig ) ;
23
- }
24
- } ) ) ;
25
- this . registerConfigurationListener ( ( updatedConfig , oldConfig ) => {
26
- if ( updatedConfig . showMembers !== oldConfig . showMembers
27
- || updatedConfig . packagePresentation !== oldConfig . packagePresentation
28
- || ( updatedConfig . syncWithFolderExplorer !== oldConfig . syncWithFolderExplorer
29
- && updatedConfig . syncWithFolderExplorer ) ) {
17
+ if ( ( e . affectsConfiguration ( "java.dependency.syncWithFolderExplorer" ) && Settings . syncWithFolderExplorer ( ) ) ||
18
+ e . affectsConfiguration ( "java.dependency.showMembers" ) ||
19
+ e . affectsConfiguration ( "java.dependency.packagePresentation" ) ) {
30
20
commands . executeCommand ( Commands . VIEW_PACKAGE_INTERNAL_REFRESH ) ;
31
- } else if ( updatedConfig . autoRefresh !== oldConfig . autoRefresh ) {
32
- syncHandler . updateFileWatcher ( updatedConfig . autoRefresh ) ;
21
+ } else if ( e . affectsConfiguration ( "java.dependency.autoRefresh" ) ) {
22
+ syncHandler . updateFileWatcher ( Settings . autoRefresh ( ) ) ;
23
+ } else if ( e . affectsConfiguration ( "java.dependency.refreshDelay" ) ) {
24
+ // TODO: getInstance() should not have parameter if it means to be a singleton.
25
+ DependencyExplorer . getInstance ( contextManager . context )
26
+ . dataProvider . setRefreshDebounceFunc ( Settings . refreshDelay ( ) ) ;
33
27
}
34
- } ) ;
28
+ } ) ) ;
35
29
36
30
syncHandler . updateFileWatcher ( Settings . autoRefresh ( ) ) ;
37
31
38
- context . subscriptions . push ( { dispose : ( ) => { this . _configurationListeners = [ ] ; } } ) ;
39
-
40
32
context . subscriptions . push ( instrumentOperationAsVsCodeCommand ( Commands . VIEW_PACKAGE_LINKWITHFOLDER , Settings . linkWithFolderCommand ) ) ;
41
33
42
34
context . subscriptions . push ( instrumentOperationAsVsCodeCommand ( Commands . VIEW_PACKAGE_UNLINKWITHFOLDER , Settings . unlinkWithFolderCommand ) ) ;
@@ -48,24 +40,20 @@ export class Settings {
48
40
Settings . changeToHierarchicalPackageView ) ) ;
49
41
}
50
42
51
- public static registerConfigurationListener ( listener : Listener ) {
52
- this . _configurationListeners . push ( listener ) ;
53
- }
54
-
55
43
public static linkWithFolderCommand ( ) : void {
56
- workspace . getConfiguration ( ) . update ( "java.dependency. syncWithFolderExplorer" , true , false ) ;
44
+ workspace . getConfiguration ( "java.dependency" ) . update ( " syncWithFolderExplorer", true , false ) ;
57
45
}
58
46
59
47
public static unlinkWithFolderCommand ( ) : void {
60
- workspace . getConfiguration ( ) . update ( "java.dependency. syncWithFolderExplorer" , false , false ) ;
48
+ workspace . getConfiguration ( "java.dependency" ) . update ( " syncWithFolderExplorer", false , false ) ;
61
49
}
62
50
63
51
public static changeToFlatPackageView ( ) : void {
64
- workspace . getConfiguration ( ) . update ( "java.dependency. packagePresentation" , PackagePresentation . Flat , false ) ;
52
+ workspace . getConfiguration ( "java.dependency" ) . update ( " packagePresentation", PackagePresentation . Flat , false ) ;
65
53
}
66
54
67
55
public static changeToHierarchicalPackageView ( ) : void {
68
- workspace . getConfiguration ( ) . update ( "java.dependency. packagePresentation" , PackagePresentation . Hierarchical , false ) ;
56
+ workspace . getConfiguration ( "java.dependency" ) . update ( " packagePresentation", PackagePresentation . Hierarchical , false ) ;
69
57
}
70
58
71
59
public static updateReferencedLibraries ( libraries : IReferencedLibraries ) : void {
@@ -77,7 +65,7 @@ export class Settings {
77
65
if ( ! updateSetting . exclude && ! updateSetting . sources ) {
78
66
updateSetting = libraries . include ;
79
67
}
80
- workspace . getConfiguration ( ) . update ( "java.project. referencedLibraries" , updateSetting ) ;
68
+ workspace . getConfiguration ( "java.project" ) . update ( " referencedLibraries", updateSetting ) ;
81
69
}
82
70
83
71
public static referencedLibraries ( ) : IReferencedLibraries {
@@ -91,42 +79,36 @@ export class Settings {
91
79
}
92
80
93
81
public static showMembers ( ) : boolean {
94
- return this . _dependencyConfig . get ( "showMembers" , false ) ;
82
+ return workspace . getConfiguration ( "java.dependency" ) . get ( "showMembers" , false ) ;
95
83
}
96
84
97
85
public static autoRefresh ( ) : boolean {
98
- return this . _dependencyConfig . get ( "autoRefresh" , true ) ;
86
+ return workspace . getConfiguration ( "java.dependency" ) . get ( "autoRefresh" , true ) ;
99
87
}
100
88
101
89
public static syncWithFolderExplorer ( ) : boolean {
102
- return this . _dependencyConfig . get ( "syncWithFolderExplorer" , true ) ;
90
+ return workspace . getConfiguration ( "java.dependency" ) . get ( "syncWithFolderExplorer" , true ) ;
103
91
}
104
92
105
93
public static isHierarchicalView ( ) : boolean {
106
- return this . _dependencyConfig . get ( "packagePresentation" ) === PackagePresentation . Hierarchical ;
94
+ return workspace . getConfiguration ( "java.dependency" ) . get ( "packagePresentation" ) === PackagePresentation . Hierarchical ;
107
95
}
108
96
109
97
public static refreshDelay ( ) : number {
110
- return this . _dependencyConfig . get ( "refreshDelay" , 2000 ) ;
98
+ return workspace . getConfiguration ( "java.dependency" ) . get ( "refreshDelay" , 2000 ) ;
111
99
}
112
100
113
101
public static getExportJarTargetPath ( ) : string {
114
102
// tslint:disable-next-line: no-invalid-template-strings
115
103
return workspace . getConfiguration ( "java.project.exportJar" ) . get < string > ( "targetPath" , "${workspaceFolder}/${workspaceFolderBasename}.jar" ) ;
116
104
}
117
-
118
- private static _dependencyConfig : WorkspaceConfiguration = workspace . getConfiguration ( "java.dependency" ) ;
119
-
120
- private static _configurationListeners : Listener [ ] = [ ] ;
121
105
}
122
106
123
107
enum PackagePresentation {
124
108
Flat = "flat" ,
125
109
Hierarchical = "hierarchical" ,
126
110
}
127
111
128
- type Listener = ( updatedConfig : WorkspaceConfiguration , oldConfig : WorkspaceConfiguration ) => void ;
129
-
130
112
export interface IReferencedLibraries {
131
113
include : string [ ] ;
132
114
exclude : string [ ] ;
0 commit comments