~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.WebReferences/MonoDevelop.WebReferences.Dialogs/WebReferenceDialog.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
using MonoDevelop.Ide;
14
14
using MonoDevelop.Projects;
15
15
using MonoDevelop.WebReferences.WS;
 
16
using MonoDevelop.WebReferences.WCF;
16
17
 
17
18
namespace MonoDevelop.WebReferences.Dialogs
18
19
{
23
24
                protected Widget browserWidget = null;
24
25
                protected IWebBrowser browser = null;
25
26
                #endregion
26
 
                
 
27
 
 
28
                enum DialogState {
 
29
                        Uninitialized,
 
30
                        Create,
 
31
                        Modify,
 
32
                        CreateConfig,
 
33
                        ModifyConfig
 
34
                }
 
35
 
 
36
                bool modified;
 
37
                bool isWebService;
 
38
                WCFConfigWidget wcfConfig;
 
39
                ClientOptions wcfOptions;
 
40
                DialogState state = DialogState.Uninitialized;
27
41
                Label docLabel;
28
42
                DotNetProject project;
29
43
                
32
46
                /// <value>True if the current location of the browser is a Web Service, otherwise false.</value>
33
47
                public bool IsWebService
34
48
                {
35
 
                        get { return btnOK.Sensitive; }
36
 
                        set 
 
49
                        get { return isWebService; }
 
50
                        private set 
37
51
                        {
38
52
                                // Clear out the Reference and Namespace Entry
39
 
                                if (btnOK.Sensitive && !value)
 
53
                                if (isWebService && !value)
40
54
                                {
41
55
                                        this.tbxReferenceName.Text = "";
42
56
                                }
43
 
                                btnOK.Sensitive = value;
44
 
                                tbxReferenceName.Sensitive = value;
 
57
                                isWebService = value;
 
58
                                ChangeState (state);
45
59
                        }
46
60
                }
47
61
                
132
146
                {
133
147
                        get { return System.IO.Path.Combine(BasePath, ReferenceName); }
134
148
                }
 
149
 
 
150
                /// Whether or not the dialog has been modified
 
151
                public bool Modified {
 
152
                        get { return modified; }
 
153
                }
135
154
                #endregion
136
155
                
137
156
                #region Member Variables
148
167
                {
149
168
                        Build();
150
169
                        this.basePath = Library.GetWebReferencePath (project);
151
 
                        this.IsWebService = false;
 
170
                        this.isWebService = false;
152
171
                        this.project = project;
 
172
                        this.modified = true;
 
173
 
 
174
                        tbxReferenceURL.Text = homeUrl;
 
175
 
 
176
                        wcfOptions = WebReferencesService.WcfEngine.DefaultClientOptions;
 
177
 
 
178
                        ChangeState (DialogState.Create);
 
179
                        frmBrowser.Show ();
 
180
                        this.Child.Show ();
 
181
                }
 
182
 
 
183
                public WebReferenceDialog (WebReferenceItem item, ClientOptions options)
 
184
                {
 
185
                        Build ();
 
186
                        this.isWebService = true;
 
187
                        this.wcfOptions = options;
 
188
                        this.namespacePrefix = item.Project.DefaultNamespace;
 
189
 
 
190
                        ChangeState (DialogState.ModifyConfig);
153
191
                        
154
 
                        // Add the mozilla control to the frame
155
 
                        if (WebBrowserService.CanGetWebBrowser) {
156
 
                                browser = WebBrowserService.GetWebBrowser ();
157
 
                                browserWidget = (Widget) browser;
158
 
                                browser.LocationChanged += Browser_LocationChanged;
159
 
                                browser.NetStart += Browser_StartLoading;
160
 
                                browser.NetStop += Browser_StopLoading;
161
 
                                frmBrowser.Add(browserWidget);
162
 
                                browser.LoadUrl(this.homeUrl);
163
 
                                browserWidget.Show();
164
 
                        } else {
165
 
                                tlbNavigate.Visible = false;
166
 
                                
167
 
                                ScrolledWindow sw = new ScrolledWindow ();
168
 
                                sw.ShadowType = ShadowType.In;
169
 
                                docLabel = new Label ();
170
 
                                docLabel.Xpad = 6;
171
 
                                docLabel.Ypad = 6;
172
 
                                docLabel.Xalign = 0;
173
 
                                docLabel.Yalign = 0;
174
 
                                sw.AddWithViewport (docLabel);
175
 
                                sw.ShowAll ();
176
 
                                
177
 
                                frmBrowser.Add (sw);
178
 
                                tbxReferenceURL.Text = homeUrl;
179
 
                                UpdateLocation ();
180
 
                        }
181
 
 
182
 
                        frmBrowser.Show();
183
 
                        this.Child.ShowAll ();
 
192
                        var service = item.Load ();
 
193
                        var url = service.GetServiceURL ();
 
194
 
 
195
                        if (service is WebServiceDiscoveryResultWCF)
 
196
                                comboModel.Active = 0;
 
197
                        else
 
198
                                comboModel.Active = 1;
 
199
 
 
200
                        UpdateService (service, url);
 
201
 
 
202
                        tbxReferenceURL.Text = url;
 
203
                        tbxReferenceName.Text = item.Name;
 
204
                        tbxNamespace.Text = item.Project.DefaultNamespace;
 
205
 
 
206
                        frmBrowser.Show ();
 
207
                        this.Child.Show ();
184
208
                }
185
209
                
186
210
                /// <summary>Execute the event when any of the buttons on the action panel has been clicked</summary>
206
230
                /// <param name="e">An EventArgs object that contains the event data.</param>
207
231
                private void Browser_GoButtonClicked (object sender, EventArgs e)
208
232
                {
 
233
                        modified = true;
 
234
                        switch (state) {
 
235
                        case DialogState.Create:
 
236
                        case DialogState.CreateConfig:
 
237
                                ChangeState (DialogState.Create);
 
238
                                break;
 
239
 
 
240
                        case DialogState.Modify:
 
241
                        case DialogState.ModifyConfig:
 
242
                                ChangeState (DialogState.Modify);
 
243
                                break;
 
244
 
 
245
                        default:
 
246
                                throw new InvalidOperationException ();
 
247
                        }
 
248
 
209
249
                        if (browser != null)
210
 
                                browser.LoadUrl(tbxReferenceURL.Text);
 
250
                                browser.LoadUrl (tbxReferenceURL.Text);
211
251
                        else
212
252
                                UpdateLocation ();
213
253
                }
231
271
                {
232
272
                        if (browser != null) {
233
273
                                this.tbxReferenceURL.Text = this.browser.Location;
234
 
                                this.btnBack.Sensitive = browser.CanGoBack;
235
 
                                this.btnNext.Sensitive = browser.CanGoForward;
 
274
                                this.btnNavBack.Sensitive = browser.CanGoBack;
 
275
                                this.btnNavNext.Sensitive = browser.CanGoForward;
236
276
                                // Query the current url for services
237
277
                                ThreadPool.QueueUserWorkItem(new WaitCallback(QueryService), this.tbxReferenceURL.Text);
238
278
                        }
311
351
                {
312
352
                        string url = param as string;
313
353
                        // Set the service url
314
 
                        lock (this)
315
 
                        {
 
354
                        lock (this) {
316
355
                                if (serviceUrl == url) 
317
356
                                        return;
318
357
                                serviceUrl = url; 
362
401
                        if (service == null) {
363
402
                                this.IsWebService = false;
364
403
                                this.selectedService = null;
365
 
                        }
366
 
                        else {
 
404
                        } else {
367
405
                                // Set the Default Namespace and Reference
368
406
                                this.tbxNamespace.Text = this.DefaultNamespace;
369
407
                                
370
 
                                string name = this.DefaultReferenceName;
371
 
                                
372
 
                                var items = WebReferencesService.GetWebReferenceItems (project);
373
 
                                if (items.Any (it => it.Name == name)) {
374
 
                                        int num = 2;
375
 
                                        while (items.Any (it => it.Name == name + "_" + num))
376
 
                                                num++;
377
 
                                        name = name + "_" + num;
 
408
                                if (project != null) {
 
409
                                        string name = this.DefaultReferenceName;
 
410
                                        
 
411
                                        var items = WebReferencesService.GetWebReferenceItems (project);
 
412
                                        if (items.Any (it => it.Name == name)) {
 
413
                                                int num = 2;
 
414
                                                while (items.Any (it => it.Name == name + "_" + num))
 
415
                                                        num++;
 
416
                                                name = name + "_" + num;
 
417
                                        }
 
418
                                        this.tbxReferenceName.Text = name;
378
419
                                }
379
 
                                this.tbxReferenceName.Text = name;
380
420
                                
381
421
                                this.IsWebService = true;
382
422
                                this.selectedService = service;
383
 
                                
 
423
 
384
424
                                if (docLabel != null) {
385
425
                                        docLabel.Wrap = false;
386
426
                                        text.Append (service.GetDescriptionMarkup ());
398
438
                
399
439
                protected virtual void OnBtnOKClicked (object sender, System.EventArgs e)
400
440
                {
 
441
                        if (wcfConfig != null) {
 
442
                                wcfConfig.Update ();
 
443
                                modified |= wcfConfig.Modified;
 
444
                        }
 
445
                        
 
446
                        if (project == null) {
 
447
                                Respond (Gtk.ResponseType.Ok);
 
448
                                return;
 
449
                        }
 
450
 
401
451
                        if (WebReferencesService.GetWebReferenceItems (project).Any (r => r.Name == this.tbxReferenceName.Text)) {
402
452
                                MessageService.ShowError (GettextCatalog.GetString ("Web reference already exists"), GettextCatalog.GetString ("A web service reference with the name '{0}' already exists in the project. Please use a different name.", this.tbxReferenceName.Text));
403
453
                                return;
417
467
                        serviceUrl = null;
418
468
                        ThreadPool.QueueUserWorkItem(new WaitCallback(QueryService), this.tbxReferenceURL.Text);
419
469
                }
 
470
 
 
471
                protected void OnBtnConfigClicked (object sender, EventArgs e)
 
472
                {
 
473
                        switch (state) {
 
474
                        case DialogState.Create:
 
475
                                ChangeState (DialogState.CreateConfig);
 
476
                                break;
 
477
                        case DialogState.Modify:
 
478
                                ChangeState (DialogState.ModifyConfig);
 
479
                                break;
 
480
                        default:
 
481
                                throw new InvalidOperationException ();
 
482
                        }
 
483
                }
 
484
 
 
485
                void ChangeState (DialogState newState)
 
486
                {
 
487
                        bool hasConfig = comboModel.Active == 0;
 
488
 
 
489
                        switch (newState) {
 
490
                        case DialogState.Create:
 
491
                                btnBack.Visible = false;
 
492
                                btnConfig.Visible = true;
 
493
                                btnConfig.Sensitive = isWebService && hasConfig;
 
494
                                btnOK.Visible = true;
 
495
                                btnOK.Sensitive = isWebService;
 
496
                                tlbNavigate.Visible = WebBrowserService.CanGetWebBrowser;
 
497
                                tbxReferenceName.Sensitive = isWebService;
 
498
                                comboModel.Sensitive = true;
 
499
                                break;
 
500
 
 
501
                        case DialogState.CreateConfig:
 
502
                                btnBack.Visible = true;
 
503
                                btnBack.Sensitive = true;
 
504
                                btnConfig.Visible = false;
 
505
                                btnOK.Visible = true;
 
506
                                btnOK.Sensitive = true;
 
507
                                tlbNavigate.Visible = false;
 
508
                                tbxReferenceName.Sensitive = false;
 
509
                                comboModel.Sensitive = false;
 
510
                                break;
 
511
 
 
512
                        case DialogState.Modify:
 
513
                                btnBack.Visible = false;
 
514
                                btnConfig.Visible = true;
 
515
                                btnConfig.Sensitive = isWebService && hasConfig;
 
516
                                btnOK.Visible = true;
 
517
                                btnOK.Sensitive = isWebService;
 
518
                                tlbNavigate.Visible = WebBrowserService.CanGetWebBrowser;
 
519
                                tbxReferenceName.Sensitive = false;
 
520
                                comboModel.Sensitive = false;
 
521
                                break;
 
522
 
 
523
                        case DialogState.ModifyConfig:
 
524
                                btnBack.Visible = false;
 
525
                                btnConfig.Visible = false;
 
526
                                btnOK.Visible = true;
 
527
                                btnOK.Sensitive = true;
 
528
                                tlbNavigate.Visible = false;
 
529
                                tbxReferenceName.Sensitive = false;
 
530
                                comboModel.Sensitive = false;
 
531
                                break;
 
532
                                
 
533
                        default:
 
534
                                throw new InvalidOperationException ();
 
535
                        }
 
536
 
 
537
                        if (wcfConfig != null)
 
538
                                wcfConfig.Update ();
 
539
 
 
540
                        if (state == newState)
 
541
                                return;
 
542
 
 
543
                        if (state != DialogState.Uninitialized)
 
544
                                frmBrowser.Forall (c => frmBrowser.Remove (c));
 
545
 
 
546
                        browser = null;
 
547
                        browserWidget = null;
 
548
                        docLabel = null;
 
549
                        wcfConfig = null;
 
550
 
 
551
                        state = newState;
 
552
                        
 
553
                        ScrolledWindow sw;
 
554
 
 
555
                        switch (state) {
 
556
                        case DialogState.Create:
 
557
                        case DialogState.Modify:
 
558
                                if (WebBrowserService.CanGetWebBrowser) {
 
559
                                        browser = WebBrowserService.GetWebBrowser ();
 
560
                                        browserWidget = (Widget) browser;
 
561
                                        browser.LocationChanged += Browser_LocationChanged;
 
562
                                        browser.NetStart += Browser_StartLoading;
 
563
                                        browser.NetStop += Browser_StopLoading;
 
564
                                        frmBrowser.Add (browserWidget);
 
565
                                        browser.LoadUrl (tbxReferenceURL.Text);
 
566
                                        browserWidget.Show ();
 
567
                                } else {
 
568
                                        docLabel = new Label ();
 
569
                                        docLabel.Xpad = 6;
 
570
                                        docLabel.Ypad = 6;
 
571
                                        docLabel.Xalign = 0;
 
572
                                        docLabel.Yalign = 0;
 
573
 
 
574
                                        sw = new ScrolledWindow ();
 
575
                                        sw.ShadowType = ShadowType.In;
 
576
                                        sw.AddWithViewport (docLabel);
 
577
                                        sw.ShowAll ();
 
578
                                        frmBrowser.Add (sw);
 
579
                                        UpdateLocation ();
 
580
                                }
 
581
                                break;
 
582
 
 
583
                        case DialogState.ModifyConfig:
 
584
                        case DialogState.CreateConfig:
 
585
                                if (!hasConfig)
 
586
                                        return;
 
587
 
 
588
                                sw = new ScrolledWindow ();
 
589
                                sw.ShadowType = ShadowType.In;
 
590
 
 
591
                                wcfConfig = new WCFConfigWidget (wcfOptions);
 
592
                                sw.AddWithViewport (wcfConfig);
 
593
                                sw.ShowAll ();
 
594
                                frmBrowser.Add (sw);
 
595
                                break;
 
596
 
 
597
                        default:
 
598
                                throw new InvalidOperationException ();
 
599
                        }
 
600
                }
 
601
 
 
602
                protected void OnBtnBackClicked (object sender, EventArgs e)
 
603
                {
 
604
                        switch (state) {
 
605
                        case DialogState.CreateConfig:
 
606
                                ChangeState (DialogState.Create);
 
607
                                break;
 
608
                        case DialogState.ModifyConfig:
 
609
                                ChangeState (DialogState.Modify);
 
610
                                break;
 
611
                        default:
 
612
                                throw new InvalidOperationException ();
 
613
                        }
 
614
                }
 
615
 
420
616
        }
421
617
        
422
618
        class AskCredentials: GuiSyncObject, ICredentials