@@ -11,19 +11,21 @@ import { removeReferencedLibrary, addLibraries } from "../classpathConfiguration
1111import { ClasspathRequest } from "../../../vscode/utils" ;
1212
1313import { ClasspathEntry , ClasspathEntryKind } from "../../../../types" ;
14- import { ProjectType } from "../../../../../utils/webview" ;
14+ import { isProjectType } from "../../../../../utils/webview" ;
1515
1616const Libraries = ( ) : JSX . Element => {
1717
1818 const [ hoveredRow , setHoveredRow ] = useState < string | null > ( null ) ;
19+ const addLibraryBtnRef = useRef < HTMLElement > ( null ) ;
1920 const activeProjectIndex : number = useSelector ( ( state : any ) => state . commonConfig . ui . activeProjectIndex ) ;
2021 const activeProjectIndexRef = useRef ( activeProjectIndex ) ;
2122 useEffect ( ( ) => {
2223 activeProjectIndexRef . current = activeProjectIndex ;
2324 } , [ activeProjectIndex ] ) ;
2425
2526 const libraries : ClasspathEntry [ ] = useSelector ( ( state : any ) => state . classpathConfig . data . libraries [ activeProjectIndex ] ) ;
26- const projectType : ProjectType = useSelector ( ( state : any ) => state . commonConfig . data . projectType [ activeProjectIndex ] ) ;
27+ const projectType : unknown = useSelector ( ( state : any ) => state . commonConfig . data . projectType [ activeProjectIndex ] ) ;
28+ const canAddLibrary = isProjectType ( projectType ) ;
2729 const dispatch : Dispatch < any > = useDispatch ( ) ;
2830
2931 const handleRemove = ( index : number ) => {
@@ -34,9 +36,22 @@ const Libraries = (): JSX.Element => {
3436 } ;
3537
3638 const handleAdd = ( ) => {
39+ if ( ! canAddLibrary ) {
40+ return ;
41+ }
3742 ClasspathRequest . onWillSelectLibraries ( projectType ) ;
3843 } ;
3944
45+ useEffect ( ( ) => {
46+ const el = addLibraryBtnRef . current ;
47+ if ( ! el ) return ;
48+ if ( canAddLibrary ) {
49+ el . removeAttribute ( "disabled" ) ;
50+ } else {
51+ el . setAttribute ( "disabled" , "" ) ;
52+ }
53+ } , [ canAddLibrary ] ) ;
54+
4055 const onDidAddLibraries = ( event : OnDidAddLibrariesEvent ) => {
4156 const { data} = event ;
4257 if ( data . command === "classpath.onDidAddLibraries" ) {
@@ -112,7 +127,7 @@ const Libraries = (): JSX.Element => {
112127 < div className = "setting-section" >
113128 < div >
114129 < div id = "list-actions" className = "flex-center setting-list-actions" >
115- < vscode-button class = "ghost-button" onClick = { ( ) => handleAdd ( ) } >
130+ < vscode-button ref = { addLibraryBtnRef } class = "ghost-button" onClick = { ( ) => handleAdd ( ) } >
116131 < span className = "codicon codicon-add mr-1" > </ span >
117132 Add Library...
118133 </ vscode-button >
0 commit comments