@@ -20,22 +20,18 @@ export function addCloneButton(model: IGitExtension, filebrowser: FileBrowser) {
20
20
'gitClone' ,
21
21
ReactWidget . create (
22
22
< UseSignal
23
- signal = { model . repositoryChanged }
23
+ signal = { filebrowser . model . pathChanged }
24
24
initialArgs = { {
25
- name : 'pathRepository ' ,
26
- oldValue : null ,
27
- newValue : model . pathRepository
25
+ name : 'path ' ,
26
+ oldValue : '/' ,
27
+ newValue : filebrowser . model . path
28
28
} }
29
29
>
30
- { ( _ , change : IChangedArgs < string | null > ) => (
31
- < ToolbarButtonComponent
32
- enabled = { change . newValue === null }
33
- iconClassName = { `${ cloneButtonStyle } jp-Icon jp-Icon-16` }
34
- onClick = { async ( ) => {
35
- await doGitClone ( model , filebrowser . model . path ) ;
36
- filebrowser . model . refresh ( ) ;
37
- } }
38
- tooltip = { 'Git Clone' }
30
+ { ( _ , change : IChangedArgs < string > ) => (
31
+ < GitCloneButton
32
+ model = { model }
33
+ filebrowser = { filebrowser }
34
+ change = { change }
39
35
/>
40
36
) }
41
37
</ UseSignal >
@@ -151,3 +147,54 @@ class GitCloneForm extends Widget {
151
147
return encodeURIComponent ( this . node . querySelector ( 'input' ) . value ) ;
152
148
}
153
149
}
150
+
151
+ /**
152
+ * Git clone toolbar button properties
153
+ */
154
+ interface IGitCloneButtonProps {
155
+ /**
156
+ * Git extension model
157
+ */
158
+ model : IGitExtension ;
159
+ /**
160
+ * File browser object
161
+ */
162
+ filebrowser : FileBrowser ;
163
+ /**
164
+ * File browser path change
165
+ */
166
+ change : IChangedArgs < string > ;
167
+ }
168
+
169
+ const GitCloneButton : React . FunctionComponent < IGitCloneButtonProps > = (
170
+ props : IGitCloneButtonProps
171
+ ) => {
172
+ const [ enable , setEnable ] = React . useState ( false ) ;
173
+
174
+ React . useEffect ( ( ) => {
175
+ model
176
+ . showTopLevel ( change . newValue )
177
+ . then ( answer => {
178
+ setEnable ( answer . code !== 0 ) ;
179
+ } )
180
+ . catch ( reason => {
181
+ console . error (
182
+ `Fail to get the top level path for ${ change . newValue } .\n${ reason } `
183
+ ) ;
184
+ } ) ;
185
+ } ) ;
186
+
187
+ const { model, filebrowser, change } = props ;
188
+
189
+ return (
190
+ < ToolbarButtonComponent
191
+ enabled = { enable }
192
+ iconClassName = { `${ cloneButtonStyle } jp-Icon jp-Icon-16` }
193
+ onClick = { async ( ) => {
194
+ await doGitClone ( model , filebrowser . model . path ) ;
195
+ filebrowser . model . refresh ( ) ;
196
+ } }
197
+ tooltip = { 'Git Clone' }
198
+ />
199
+ ) ;
200
+ } ;
0 commit comments