30
30
using System . Net ;
31
31
using MonoDevelop . VersionControl . TFS . Helpers ;
32
32
using MonoDevelop . Ide ;
33
+ using Microsoft . TeamFoundation . Client ;
34
+ using System . Linq ;
35
+ using GLib ;
36
+ using System . Collections . Generic ;
37
+ using MonoDevelop . Ide . Gui ;
38
+ using MonoDevelop . Projects ;
33
39
34
40
namespace MonoDevelop . VersionControl . TFS . GUI
35
41
{
@@ -107,8 +113,22 @@ void OnAddServer(object sender, EventArgs e)
107
113
MessageService . ShowWarning ( "No keyring service found!\n Password has been saved as plain text in server URL" ) ;
108
114
}
109
115
uriBuilder . Password = credentialsDialog . Credentials . Password ;
110
- TFSVersionControlService . Instance . AddServer ( dialog . Name , uriBuilder . Uri ) ;
111
- UpdateServersList ( ) ;
116
+ TeamFoundationServer server = new TeamFoundationServer ( uriBuilder . Uri , dialog . Name , credentialsDialog . Credentials ) ;
117
+ using ( var projectCollectionDialog = new ChooseProjectsDialog ( server ) )
118
+ {
119
+ if ( projectCollectionDialog . Run ( this ) == Command . Ok && projectCollectionDialog . SelectedProjects . Any ( ) )
120
+ {
121
+ var newServer = new TeamFoundationServer ( uriBuilder . Uri , dialog . Name , credentialsDialog . Credentials ) ;
122
+ newServer . LoadProjectConnections ( projectCollectionDialog . SelectedProjects . Select ( x => x . Collection . Id ) . ToList ( ) ) ;
123
+ foreach ( var c in newServer . ProjectCollections )
124
+ {
125
+ var c1 = c ;
126
+ c . LoadProjects ( projectCollectionDialog . SelectedProjects . Where ( p => string . Equals ( c1 . Name , p . Collection . Name ) ) . Select ( x => x . Name ) . ToList ( ) ) ;
127
+ }
128
+ TFSVersionControlService . Instance . AddServer ( newServer ) ;
129
+ UpdateServersList ( ) ;
130
+ }
131
+ }
112
132
}
113
133
}
114
134
}
@@ -132,7 +152,7 @@ private void UpdateServersList()
132
152
{
133
153
var row = _store . AddRow ( ) ;
134
154
_store . SetValue ( row , _name , server . Name ) ;
135
- _store . SetValue ( row , _url , server . Url . ToString ( ) ) ;
155
+ _store . SetValue ( row , _url , server . Uri . ToString ( ) ) ;
136
156
}
137
157
}
138
158
}
@@ -308,5 +328,111 @@ public NetworkCredential Credentials
308
328
}
309
329
}
310
330
}
331
+
332
+ public class ChooseProjectsDialog : Dialog
333
+ {
334
+ readonly ListStore collectionStore ;
335
+ readonly ListBox collectionsList = new ListBox ( ) ;
336
+ readonly DataField < string > collectionName = new DataField < string > ( ) ;
337
+ readonly DataField < ProjectCollection > collectionItem = new DataField < ProjectCollection > ( ) ;
338
+ readonly TreeStore projectsStore ;
339
+ readonly TreeView projectsList = new TreeView ( ) ;
340
+ readonly DataField < bool > isProjectSelected = new DataField < bool > ( ) ;
341
+ readonly DataField < string > projectName = new DataField < string > ( ) ;
342
+ readonly DataField < ProjectInfo > projectItem = new DataField < ProjectInfo > ( ) ;
343
+
344
+ public List < ProjectInfo > SelectedProjects { get ; set ; }
345
+
346
+ public ChooseProjectsDialog ( TeamFoundationServer server )
347
+ {
348
+ collectionStore = new ListStore ( collectionName , collectionItem ) ;
349
+ projectsStore = new TreeStore ( isProjectSelected , projectName , projectItem ) ;
350
+ BuildGui ( ) ;
351
+ LoadData ( server ) ;
352
+ SelectedProjects = new List < ProjectInfo > ( ) ;
353
+ }
354
+
355
+ void BuildGui ( )
356
+ {
357
+ this . Title = "Select Projects" ;
358
+ this . Resizable = false ;
359
+ var vBox = new VBox ( ) ;
360
+ var hbox = new HBox ( ) ;
361
+ collectionsList . DataSource = collectionStore ;
362
+ collectionsList . Views . Add ( new TextCellView ( collectionName ) ) ;
363
+ collectionsList . MinWidth = 200 ;
364
+ collectionsList . MinHeight = 300 ;
365
+ hbox . PackStart ( collectionsList ) ;
366
+
367
+ projectsList . DataSource = projectsStore ;
368
+ projectsList . MinWidth = 200 ;
369
+ projectsList . MinHeight = 300 ;
370
+ var checkView = new CheckBoxCellView ( isProjectSelected ) { Editable = true } ;
371
+ checkView . Toggled += ( sender , e ) =>
372
+ {
373
+ var row = projectsList . CurrentEventRow ;
374
+ var node = projectsStore . GetNavigatorAt ( row ) ;
375
+ var isSelected = ! node . GetValue ( isProjectSelected ) ; //Xwt gives previous value
376
+ var project = node . GetValue ( projectItem ) ;
377
+ if ( isSelected && ! SelectedProjects . Any ( p => string . Equals ( p . Name , project . Name ) ) )
378
+ {
379
+ SelectedProjects . Add ( project ) ;
380
+ }
381
+ if ( ! isSelected && SelectedProjects . Any ( p => string . Equals ( p . Name , project . Name ) ) )
382
+ {
383
+ SelectedProjects . RemoveAll ( p => string . Equals ( p . Name , project . Name ) ) ;
384
+ }
385
+ } ;
386
+ projectsList . Columns . Add ( new ListViewColumn ( "" , checkView ) ) ;
387
+ projectsList . Columns . Add ( new ListViewColumn ( "Name" , new TextCellView ( projectName ) ) ) ;
388
+ hbox . PackEnd ( projectsList ) ;
389
+
390
+ vBox . PackStart ( hbox ) ;
391
+
392
+ Button ok = new Button ( GettextCatalog . GetString ( "OK" ) ) ;
393
+ ok . Clicked += ( sender , e ) => Respond ( Command . Ok ) ;
394
+
395
+ Button cancel = new Button ( GettextCatalog . GetString ( "Cancel" ) ) ;
396
+ cancel . Clicked += ( sender , e ) => Respond ( Command . Cancel ) ;
397
+
398
+ ok . MinWidth = cancel . MinWidth = Constants . ButtonWidth ;
399
+
400
+ var buttonBox = new HBox ( ) ;
401
+ buttonBox . PackEnd ( ok ) ;
402
+ buttonBox . PackEnd ( cancel ) ;
403
+ vBox . PackStart ( buttonBox ) ;
404
+
405
+ this . Content = vBox ;
406
+ }
407
+
408
+ void LoadData ( TeamFoundationServer server )
409
+ {
410
+ server . LoadProjectConnections ( ) ;
411
+ server . ProjectCollections . ForEach ( c => c . LoadProjects ( ) ) ;
412
+ foreach ( var col in server . ProjectCollections )
413
+ {
414
+ var row = collectionStore . AddRow ( ) ;
415
+ collectionStore . SetValue ( row , collectionName , col . Name ) ;
416
+ collectionStore . SetValue ( row , collectionItem , col ) ;
417
+ }
418
+ collectionsList . SelectionChanged += ( sender , e ) =>
419
+ {
420
+ if ( collectionsList . SelectedRow > - 1 )
421
+ {
422
+ var collection = collectionStore . GetValue ( collectionsList . SelectedRow , collectionItem ) ;
423
+ projectsStore . Clear ( ) ;
424
+ foreach ( var project in collection . Projects )
425
+ {
426
+ var node = projectsStore . AddNode ( ) ;
427
+ node . SetValue ( isProjectSelected , false ) ;
428
+ node . SetValue ( projectName , project . Name ) ;
429
+ node . SetValue ( projectItem , project ) ;
430
+ }
431
+ }
432
+ } ;
433
+ if ( server . ProjectCollections . Any ( ) )
434
+ collectionsList . SelectRow ( 0 ) ;
435
+ }
436
+ }
311
437
}
312
438
0 commit comments