Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BreakpointPropertiesDialog.cs « MonoDevelop.Debugger « MonoDevelop.Debugger « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ccdb54b71da6feec0055d9ad89b69d48484c763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
//
// BreakpointsPropertiesDialog.cs
//
// Author:
//       Therzok <teromario@yahoo.com>
//
// Copyright (c) 2013 Therzok
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using Mono.Debugging.Client;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide;
using System.Collections.Generic;
using MonoDevelop.Ide.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
using MonoDevelop.Ide.CodeCompletion;
using Xwt;
using Xwt.Drawing;
using System.Linq;
using System.IO;
using ICSharpCode.NRefactory6.CSharp;

namespace MonoDevelop.Debugger
{
	enum ConditionalHitWhen
	{
		ResetCondition,
		ConditionIsTrue,
		ExpressionChanges
	}

	public enum BreakpointType
	{
		Location,
		Function,
		Catchpoint
	}

	sealed class BreakpointPropertiesDialog : Dialog
	{
		// For button sensitivity.
		DialogButton buttonOk;
		bool editing;

		// Groupings for sensitivity
		HBox hboxFunction = new HBox (){ MarginLeft = 18 };
		HBox hboxLocation = new HBox ();
		HBox hboxException = new HBox ();
		HBox hboxCondition = new HBox ();
		VBox vboxException = new VBox (){ MarginLeft = 18 };
		VBox vboxLocation = new VBox (){ MarginLeft = 18 };
		// Breakpoint Action radios.
		readonly RadioButton breakpointActionPause = new RadioButton (GettextCatalog.GetString ("Pause the program"));
		readonly RadioButton breakpointActionPrint = new RadioButton (GettextCatalog.GetString ("Print a message and continue"));

		// Stop-type radios.
		readonly RadioButton stopOnFunction = new RadioButton (GettextCatalog.GetString ("When a function is entered"));
		readonly RadioButton stopOnLocation = new RadioButton (GettextCatalog.GetString ("When a location is reached"));
		readonly RadioButton stopOnException = new RadioButton (GettextCatalog.GetString ("When an exception is thrown"));

		// Text entries
		readonly TextEntry entryFunctionName = new TextEntry (){ PlaceholderText = GettextCatalog.GetString ("e.g. System.Object.ToString") };
		readonly TextEntry entryLocationFile = new TextEntry (){ PlaceholderText = GettextCatalog.GetString ("e.g. Program.cs:15:5") };
		readonly TextEntryWithCodeCompletion entryExceptionType = new TextEntryWithCodeCompletion (){ PlaceholderText = GettextCatalog.GetString ("e.g. System.InvalidOperationException") };
		readonly TextEntry entryConditionalExpression = new TextEntry (){ PlaceholderText = GettextCatalog.GetString ("e.g. colorName == \"Red\"") };
		readonly TextEntry entryPrintExpression = new TextEntry () { PlaceholderText = GettextCatalog.GetString ("e.g. Value of 'name' is {name}") };

		// Warning icon
		readonly ImageViewWithTooltip warningFunction = new ImageViewWithTooltip (ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu));
		readonly ImageViewWithTooltip warningLocation = new ImageViewWithTooltip (ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu));
		readonly ImageViewWithTooltip warningException = new ImageViewWithTooltip (ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu));
		readonly ImageViewWithTooltip warningCondition = new ImageViewWithTooltip (ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu));
		readonly ImageViewWithTooltip warningPrintExpression = new ImageViewWithTooltip (ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu));

		//This class was created because normal TooltipText sometimes didn't appear seems like GTK# bug
		class ImageViewWithTooltip : Xwt.Widget
		{
			string tip;
			Xwt.Drawing.Image icon;
			Xwt.ImageView image;

			MonoDevelop.Components.TooltipPopoverWindow tooltipWindow;
			bool mouseOver;

			public ImageViewWithTooltip (Xwt.Drawing.Image icon)
			{
				this.icon = icon;
				image = new Xwt.ImageView (icon);
				this.Content = image;

				MouseEntered += HandleEnterNotifyEvent;
				MouseExited += HandleLeaveNotifyEvent;
			}

			[GLib.ConnectBefore]
			void HandleLeaveNotifyEvent (object sender, EventArgs e)
			{
				mouseOver = false;
				HideTooltip ();
			}

			[GLib.ConnectBefore]
			void HandleEnterNotifyEvent (object sender, EventArgs e)
			{
				mouseOver = true;
				ShowTooltip ();
			}

			bool ShowTooltip ()
			{
				if (!string.IsNullOrEmpty (tip)) {
					HideTooltip ();
					tooltipWindow = new MonoDevelop.Components.TooltipPopoverWindow ();
					tooltipWindow.ShowArrow = true;
					tooltipWindow.Text = tip;
					var rect = this.ScreenBounds;
					tooltipWindow.ShowPopup ((Gtk.Widget)Xwt.Toolkit.CurrentEngine.GetNativeWidget (this),
						new Gdk.Rectangle ((int)(ParentWindow.X - rect.X), (int)(ParentWindow.Y - rect.Y), (int)rect.Width, (int)rect.Height), 
						MonoDevelop.Components.PopupPosition.Bottom);
				}
				return false;
			}

			void HideTooltip ()
			{
				if (tooltipWindow != null) {
					tooltipWindow.Destroy ();
					tooltipWindow = null;
				}
			}

			protected override void Dispose (bool disposing)
			{
				HideTooltip ();
				base.Dispose (disposing);
			}

			public string ToolTip {
				get { return tip; }
				set {
					tip = value;
					if (tooltipWindow != null) {
						if (!string.IsNullOrEmpty (tip))
							tooltipWindow.Text = value;
						else
							HideTooltip ();
					} else if (!string.IsNullOrEmpty (tip) && mouseOver)
						ShowTooltip ();
				}
			}

			public Xwt.Drawing.Image Image {
				get { return icon; }
				set {
					icon = value;
					image.Image = icon;
				}
			}
		}

		// Combobox + Pager
		readonly SpinButton ignoreHitCount = new SpinButton ();
		readonly ComboBox ignoreHitType = new ComboBox ();
		readonly ComboBox conditionalHitType = new ComboBox ();

		// Optional checkboxes.
		readonly CheckBox checkIncludeSubclass = new CheckBox (GettextCatalog.GetString ("Include subclasses"));

		// Tips labels.
		readonly Label printMessageTip = new Label (GettextCatalog.GetString ("Place simple C# expressions within {} to interpolate them.")) {
			Sensitive = false,
			TextAlignment = Alignment.End
		};
		readonly Label conditionalExpressionTip = new Label (GettextCatalog.GetString ("A C# boolean expression. Scope is local to the breakpoint.")) {
			Sensitive = false,
			TextAlignment = Alignment.End
		};

		ParsedLocation breakpointLocation = new ParsedLocation ();

		BreakEvent be;
		string[] parsedParamTypes;
		string parsedFunction;
		readonly HashSet<string> classes = new HashSet<string> ();

		public BreakpointPropertiesDialog (BreakEvent be, BreakpointType breakpointType)
		{
			this.be = be;
			LoadExceptionList ();
			Initialize ();
			SetInitialData ();
			SetLayout ();
			if (be == null) {
				switch (breakpointType) {
				case BreakpointType.Location:
					stopOnLocation.Active = true;
					entryLocationFile.SetFocus ();
					break;
				case BreakpointType.Function:
					stopOnFunction.Active = true;
					entryFunctionName.SetFocus ();
					break;
				case BreakpointType.Catchpoint:
					stopOnException.Active = true;
					entryExceptionType.SetFocus ();
					break;
				}
			}
		}

		void Initialize ()
		{
			Title = GettextCatalog.GetString (be == null ? "Create a Breakpoint" : "Edit Breakpoint");
			var buttonLabel = GettextCatalog.GetString (be == null ? "Create" : "Apply");

			var actionGroup = new RadioButtonGroup ();
			breakpointActionPause.Group = actionGroup;
			breakpointActionPrint.Group = actionGroup;

			var stopGroup = new RadioButtonGroup ();
			stopOnFunction.Group = stopGroup;
			stopOnLocation.Group = stopGroup;
			stopOnException.Group = stopGroup;

			ignoreHitType.Items.Add (HitCountMode.None, GettextCatalog.GetString ("Reset condition"));
			ignoreHitType.Items.Add (HitCountMode.LessThan, GettextCatalog.GetString ("When hit count is less than"));
			ignoreHitType.Items.Add (HitCountMode.LessThanOrEqualTo, GettextCatalog.GetString ("When hit count is less than or equal to"));
			ignoreHitType.Items.Add (HitCountMode.EqualTo, GettextCatalog.GetString ("When hit count is equal to"));
			ignoreHitType.Items.Add (HitCountMode.GreaterThan, GettextCatalog.GetString ("When hit count is greater than"));
			ignoreHitType.Items.Add (HitCountMode.GreaterThanOrEqualTo, GettextCatalog.GetString ("When hit count is greater than or equal to"));
			ignoreHitType.Items.Add (HitCountMode.MultipleOf, GettextCatalog.GetString ("When hit count is a multiple of"));

			ignoreHitCount.IncrementValue = 1;
			ignoreHitCount.Digits = 0;
			ignoreHitCount.ClimbRate = 1;
			ignoreHitCount.MinimumValue = 0;
			ignoreHitCount.MaximumValue = Int32.MaxValue;


			conditionalHitType.Items.Add (ConditionalHitWhen.ResetCondition, GettextCatalog.GetString ("Reset condition"));
			conditionalHitType.Items.Add (ConditionalHitWhen.ConditionIsTrue, GettextCatalog.GetString ("And the following condition is true"));
			conditionalHitType.Items.Add (ConditionalHitWhen.ExpressionChanges, GettextCatalog.GetString ("And the following expression changes"));

			buttonOk = new DialogButton (buttonLabel, Command.Ok) {
				Sensitive = false
			};

			// Register events.
			stopGroup.ActiveRadioButtonChanged += OnUpdateControls;
			entryFunctionName.Changed += OnUpdateControls;
			entryLocationFile.Changed += OnUpdateControls;

			entryConditionalExpression.Changed += OnUpdateControls;
			ignoreHitType.SelectionChanged += OnUpdateControls;
			conditionalHitType.SelectionChanged += OnUpdateControls;
			breakpointActionPause.ActiveChanged += OnUpdateControls;
			breakpointActionPrint.ActiveChanged += OnUpdateControls;

			entryFunctionName.Changed += OnUpdateText;
			entryLocationFile.Changed += OnUpdateText;
			entryExceptionType.Changed += OnUpdateText;
			entryPrintExpression.Changed += OnUpdateText;

			buttonOk.Clicked += OnSave;

			CompletionWindowManager.WindowShown += HandleCompletionWindowShown;
			CompletionWindowManager.WindowClosed += HandleCompletionWindowClosed;
		}

		#region Modal and Dialog.Run workaround
		/*
		 * If Dialog is ran with Dialog.Run and Modal=true it takes all events like mouse, keyboard... from other windows.
		 * So when CodeCompletionList window appears mouse events don't work on it(except if CodeCompletionList.Modal=true, but then
		 * events don't work on BreakpointPropertiesDialog(can't type rest of exception type name)).
		 * So what this workaround does is disables Modal on BreakpointProperties so CodeCompletionList mouse events work fine. But if user
		 * tries to access anything outside this two windows(e.g. MainWindow). CodeCompletionList loses focus and closes itself. Resulting
		 * in BreakpointProperties.Modal = true and user can't do anything on MainWindow.
		 * All this is done so fast(or in correct order) that user can't notice this Modal switching.
		 */

		void HandleCompletionWindowClosed (object sender, EventArgs e)
		{
			var gtkWidget = Xwt.Toolkit.CurrentEngine.GetNativeWidget (vboxLocation) as Gtk.Widget;//Any widget is fine
			if (gtkWidget != null) {
				var topWindow = gtkWidget.Toplevel as Gtk.Window;
				if (topWindow != null) {
					topWindow.Modal = true;
				}
			}
		}

		void HandleCompletionWindowShown (object sender, EventArgs e)
		{
			var gtkWidget = Xwt.Toolkit.CurrentEngine.GetNativeWidget (vboxLocation) as Gtk.Widget;//Any widget is fine
			if (gtkWidget != null) {
				var topWindow = gtkWidget.Toplevel as Gtk.Window;
				if (topWindow != null) {
					topWindow.Modal = false;
				}
			}
		}

		#endregion

		void SetInitialFunctionBreakpointData (FunctionBreakpoint fb)
		{
			stopOnLocation.Visible = false;
			vboxLocation.Visible = false;
			stopOnException.Visible = false;
			vboxException.Visible = false;

			stopOnFunction.Active = true;
			if (fb.ParamTypes != null) {
				// FIXME: support non-C# syntax based on fb.Language
				entryFunctionName.Text = fb.FunctionName + " (" + String.Join (", ", fb.ParamTypes) + ")";
			} else
				entryFunctionName.Text = fb.FunctionName;
		}

		void SetInitialBreakpointData (Breakpoint bp)
		{
			stopOnFunction.Visible = false;
			hboxFunction.Visible = false;
			stopOnException.Visible = false;
			vboxException.Visible = false;

			stopOnLocation.Active = true;
			breakpointLocation.Update (bp);

			entryLocationFile.Text = breakpointLocation.ToString ();
			Project project = null;
			if (!string.IsNullOrEmpty (bp.FileName))
				project = IdeApp.Workspace.GetProjectsContainingFile (bp.FileName).FirstOrDefault ();

			if (project != null) {
				// Check the startup project of the solution too, since the current project may be a library
				SolutionItem startup = project.ParentSolution.StartupItem;
				entryConditionalExpression.Sensitive = DebuggingService.IsFeatureSupported (project, DebuggerFeatures.ConditionalBreakpoints) ||
				DebuggingService.IsFeatureSupported (startup, DebuggerFeatures.ConditionalBreakpoints);

				bool canTrace = DebuggingService.IsFeatureSupported (project, DebuggerFeatures.Tracepoints) ||
				                DebuggingService.IsFeatureSupported (startup, DebuggerFeatures.Tracepoints);

				breakpointActionPause.Sensitive = canTrace;
				entryPrintExpression.Sensitive = canTrace;
			}
		}

		void SetInitialCatchpointData (Catchpoint cp)
		{
			stopOnFunction.Visible = false;
			hboxFunction.Visible = false;
			stopOnLocation.Visible = false;
			vboxLocation.Visible = false;

			stopOnException.Active = true;
			entryExceptionType.Text = cp.ExceptionName;
			checkIncludeSubclass.Active = cp.IncludeSubclasses;
		}

		void SetInitialData ()
		{
			if (be != null) {
				editing = true;
				if (be.HitCountMode == HitCountMode.None) {
					ignoreHitType.SelectedItem = HitCountMode.GreaterThanOrEqualTo;
					ignoreHitCount.Value = 0;
				} else {
					ignoreHitType.SelectedItem = be.HitCountMode;
					ignoreHitCount.Value = be.HitCount;
				}

				if ((be.HitAction & HitAction.Break) == HitAction.Break) {
					breakpointActionPause.Active = true;
				} else {
					breakpointActionPrint.Active = true;
					entryPrintExpression.Text = be.TraceExpression;
				}

				entryConditionalExpression.Text = be.ConditionExpression ?? "";
				conditionalHitType.SelectedItem = be.BreakIfConditionChanges ?
					ConditionalHitWhen.ExpressionChanges : ConditionalHitWhen.ConditionIsTrue;


				var fb = be as FunctionBreakpoint;
				if (fb != null) {
					SetInitialFunctionBreakpointData (fb);
				} else {
					var bp = be as Breakpoint;
					if (bp != null)
						SetInitialBreakpointData (bp);
				}
				var cp = be as Catchpoint;
				if (cp != null)
					SetInitialCatchpointData (cp);
			} else {
				ignoreHitType.SelectedItem = HitCountMode.GreaterThanOrEqualTo;
				conditionalHitType.SelectedItem = ConditionalHitWhen.ConditionIsTrue;
				checkIncludeSubclass.Active = true;

				if (IdeApp.Workbench.ActiveDocument != null &&
				    IdeApp.Workbench.ActiveDocument.Editor != null &&
				    IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null) {
					breakpointLocation.Update (IdeApp.Workbench.ActiveDocument.FileName,
						IdeApp.Workbench.ActiveDocument.Editor.CaretLine,
						IdeApp.Workbench.ActiveDocument.Editor.CaretColumn);
					entryLocationFile.Text = breakpointLocation.ToString ();
					stopOnLocation.Active = true;
				}
			}
		}

		void SaveFunctionBreakpoint (FunctionBreakpoint fb)
		{
			fb.FunctionName = parsedFunction;
			fb.ParamTypes = parsedParamTypes;
		}

		class ParsedLocation
		{
			int line;
			int column;

			public void Update (string location)
			{
				if (string.IsNullOrWhiteSpace (location)) {
					Warning = GettextCatalog.GetString ("Enter location");
					return;
				}
				var splitted = location.Split (':');
				if (!File.Exists (splitted [0])) {
					//Maybe it's C:\filepath.ext
					if (splitted.Length > 1 && File.Exists (splitted [0] + ":" + splitted [1])) {
						var newSplitted = new string[splitted.Length - 1];
						newSplitted [0] = splitted [0] + ":" + splitted [1];
						for (int i = 2; i < splitted.Length; i++) {
							newSplitted [i - 1] = splitted [i];
						}
						splitted = newSplitted;
					} else {
						Warning = GettextCatalog.GetString ("File does not exist");
						return;
					}
				}
				if (splitted.Length < 2) {
					Warning = GettextCatalog.GetString ("Missing ':' for line declaration");
					return;
				}
				FileName = splitted [0];
				if (!int.TryParse (splitted [1], out line)) {
					Warning = GettextCatalog.GetString ("Line is not a number");
					return;
				}

				if (splitted.Length > 2 && !int.TryParse (splitted [2], out column)) {
					Warning = GettextCatalog.GetString ("Column is not a number");
					return;
				} else {
					column = 1;
				}
				Warning = "";
			}

			public void Update (Breakpoint bp)
			{
				Update (bp.FileName, bp.Line, bp.Column);
			}

			public void Update (string filePath, int line, int column)
			{
				if (!System.IO.File.Exists (filePath)) {
					Warning = GettextCatalog.GetString ("File does not exist");
				} else {
					Warning = "";
				}
				this.FileName = filePath;
				this.line = line;
				this.column = column;
			}

			public Breakpoint ToBreakpoint ()
			{
				if (!IsValid)
					throw new InvalidOperationException ("Location is invalid.");
				return new Breakpoint (FileName, line, column);
			}

			public string Warning { get; private set; }

			public bool IsValid {
				get {
					return Warning == "";
				}
			}

			public string FileName { get; private set; }

			public int Line { get { return line; } }

			public int Column { get { return column; } }

			public override string ToString ()
			{
				return FileName + ":" + line + ":" + column;
			}
		}

		void SaveBreakpoint (Breakpoint bp)
		{
			bp.SetColumn (breakpointLocation.Column);
			bp.SetLine (breakpointLocation.Line);
		}

		void OnSave (object sender, EventArgs e)
		{
			if (be == null) {
				if (stopOnFunction.Active)
					be = new FunctionBreakpoint ("", "C#");
				else if (stopOnLocation.Active)
					be = breakpointLocation.ToBreakpoint ();
				else if (stopOnException.Active)
					be = new Catchpoint (entryExceptionType.Text, checkIncludeSubclass.Active);
				else
					return;
			}

			var fb = be as FunctionBreakpoint;
			if (fb != null)
				SaveFunctionBreakpoint (fb);

			var bp = be as Breakpoint;
			if (bp != null)
				SaveBreakpoint (bp);

			if ((HitCountMode)ignoreHitType.SelectedItem == HitCountMode.GreaterThanOrEqualTo && (int)ignoreHitCount.Value == 0) {
				be.HitCountMode = HitCountMode.None;
			} else {
				be.HitCountMode = (HitCountMode)ignoreHitType.SelectedItem;
			}
			be.HitCount = be.HitCountMode != HitCountMode.None ? (int)ignoreHitCount.Value : 0;


			if (!string.IsNullOrWhiteSpace (entryConditionalExpression.Text)) {
				be.ConditionExpression = entryConditionalExpression.Text;
				be.BreakIfConditionChanges = conditionalHitType.SelectedItem.Equals (ConditionalHitWhen.ExpressionChanges);
			} else {
				be.ConditionExpression = null;
			}

			if (breakpointActionPrint.Active) {
				be.HitAction = HitAction.PrintExpression;
				be.TraceExpression = entryPrintExpression.Text;
			} else {
				be.HitAction = HitAction.Break;
			}
			be.CommitChanges ();
		}

		void OnUpdateControls (object sender, EventArgs e)
		{
			//Selection of None actually means ResetCondition
			if (ignoreHitType.SelectedItem != null && (HitCountMode)ignoreHitType.SelectedItem == HitCountMode.None) {
				ignoreHitType.SelectedItem = HitCountMode.GreaterThanOrEqualTo;
				ignoreHitCount.Value = 0;
			}

			if (conditionalHitType.SelectedItem != null && (ConditionalHitWhen)conditionalHitType.SelectedItem == ConditionalHitWhen.ResetCondition) {
				conditionalHitType.SelectedItem = ConditionalHitWhen.ConditionIsTrue;
				entryConditionalExpression.Text = "";
			}

			// Check which radio is selected.
			hboxFunction.Sensitive = stopOnFunction.Active && DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints) && !editing;
			hboxLocation.Sensitive = stopOnLocation.Active && DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints) && !editing;
			hboxException.Sensitive = stopOnException.Active && DebuggingService.IsFeatureSupported (DebuggerFeatures.Catchpoints) && !editing;
			checkIncludeSubclass.Sensitive = stopOnException.Active && !editing;
			hboxCondition.Sensitive = DebuggingService.IsFeatureSupported (DebuggerFeatures.ConditionalBreakpoints);

			// Check printing an expression.
			entryPrintExpression.Sensitive = breakpointActionPrint.Active && DebuggingService.IsFeatureSupported (DebuggerFeatures.Tracepoints);

			// And display warning icons
			buttonOk.Sensitive = CheckValidity ();
		}

		void OnUpdateText (object sender, EventArgs e)
		{
			buttonOk.Sensitive = CheckValidity ();
		}

		bool CheckValidity ()
		{
			warningFunction.Hide ();
			warningLocation.Hide ();
			warningException.Hide ();
			warningCondition.Hide ();
			warningPrintExpression.Hide ();

			bool result = true;

			if (breakpointActionPrint.Active && string.IsNullOrWhiteSpace (entryPrintExpression.Text)) {
				warningPrintExpression.Show ();
				warningPrintExpression.ToolTip = GettextCatalog.GetString ("Trace expression not specified");
				result = false;
			}

			if (stopOnFunction.Active) {
				string text = entryFunctionName.Text.Trim ();

				if (stopOnFunction.Active) {
					if (text.Length == 0) {
						warningFunction.Show ();
						warningFunction.ToolTip = GettextCatalog.GetString ("Function name not specified");
						result = false;
					}

					if (!TryParseFunction (text, out parsedFunction, out parsedParamTypes)) {
						warningFunction.Show ();
						warningFunction.ToolTip = GettextCatalog.GetString ("Invalid function syntax");
						result = false;
					}
				}
			} else if (stopOnLocation.Active) {
				breakpointLocation.Update (entryLocationFile.Text);
				if (!breakpointLocation.IsValid) {
					warningLocation.Show ();
					warningLocation.ToolTip = breakpointLocation.Warning;
					result = false;
				}
			} else if (stopOnException.Active) {
				if (!classes.Contains (entryExceptionType.Text)) {
					warningException.Show ();
					warningException.ToolTip = GettextCatalog.GetString ("Exception not identified");
					result = false;
				}
			}
			return result;
		}

		static bool TryParseFunction (string signature, out string function, out string[] paramTypes)
		{
			int paramListStart = signature.IndexOf ('(');
			int paramListEnd = signature.IndexOf (')');

			if (paramListStart == -1 && paramListEnd == -1) {
				function = signature;
				paramTypes = null;
				return true;
			}

			if (paramListEnd != signature.Length - 1) {
				paramTypes = null;
				function = null;
				return false;
			}

			function = signature.Substring (0, paramListStart).Trim ();

			paramListStart++;

			if (!FunctionBreakpoint.TryParseParameters (signature, paramListStart, paramListEnd, out paramTypes)) {
				paramTypes = null;
				function = null;
				return false;
			}

			return true;
		}

		void LoadExceptionList ()
		{
			classes.Add ("System.Exception");
			if (IdeApp.ProjectOperations.CurrentSelectedProject != null) {
				var compilation = TypeSystemService.GetCompilationAsync (IdeApp.ProjectOperations.CurrentSelectedProject).Result;
				var exceptionClass = compilation.GetTypeByMetadataName ("System.Exception");
				foreach (var t in compilation.GlobalNamespace.GetAllTypes ().Where ((arg) => arg.IsDerivedFromClass (exceptionClass))) {
					classes.Add (t.GetFullMetadataName ());
				}
			} else {
				//no need to unload this assembly context, it's not cached.
				var dummyProjectId = Microsoft.CodeAnalysis.ProjectId.CreateNewId ("GetExceptionsProject");
				var compilation = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create ("GetExceptions")
										   .AddReferences (MetadataReferenceCache.LoadReference (dummyProjectId, System.Reflection.Assembly.GetAssembly (typeof(object)).Location))//corlib
										   .AddReferences (MetadataReferenceCache.LoadReference (dummyProjectId, System.Reflection.Assembly.GetAssembly (typeof(Uri)).Location));//System.dll

				var exceptionClass = compilation.GetTypeByMetadataName ("System.Exception");
				foreach (var t in compilation.GlobalNamespace.GetAllTypes ().Where ((arg) => arg.IsDerivedFromClass (exceptionClass))) {
					classes.Add (t.GetFullMetadataName ());
				}
				MetadataReferenceCache.RemoveReferences (dummyProjectId);
			}
			entryExceptionType.SetCodeCompletionList (classes.ToList ());
		}

		public BreakEvent GetBreakEvent ()
		{
			return be;
		}

		void SetLayout ()
		{
			var vbox = new VBox ();
			vbox.MinWidth = 450;

			vbox.PackStart (new Label (GettextCatalog.GetString ("Breakpoint Action")) {
				Font = vbox.Font.WithWeight (FontWeight.Bold)
			});

			var breakpointActionGroup = new VBox {
				MarginLeft = 12
			};

			breakpointActionGroup.PackStart (breakpointActionPause);
			breakpointActionGroup.PackStart (breakpointActionPrint);

			var printExpressionGroup = new HBox {
				MarginLeft = 18
			};

			printExpressionGroup.PackStart (entryPrintExpression, true);
			printExpressionGroup.PackStart (warningPrintExpression);
			breakpointActionGroup.PackStart (printExpressionGroup);

			breakpointActionGroup.PackEnd (printMessageTip);

			vbox.PackStart (breakpointActionGroup);

			vbox.PackStart (new Label (GettextCatalog.GetString ("When to Take Action")) {
				Font = vbox.Font.WithWeight (FontWeight.Bold)
			});

			var whenToTakeActionRadioGroup = new VBox {
				MarginLeft = 12
			};

			// Function group
			{
				whenToTakeActionRadioGroup.PackStart (stopOnFunction);

				hboxFunction.PackStart (entryFunctionName, true);
				hboxFunction.PackEnd (warningFunction);

				whenToTakeActionRadioGroup.PackStart (hboxFunction);
			}

			// Exception group
			{
				whenToTakeActionRadioGroup.PackStart (stopOnException);

				hboxException = new HBox ();
				hboxException.PackStart (entryExceptionType, true);
				hboxException.PackEnd (warningException);

				vboxException.PackStart (hboxException);
				vboxException.PackStart (checkIncludeSubclass);
				whenToTakeActionRadioGroup.PackStart (vboxException);
			}

			// Location group
			{
				whenToTakeActionRadioGroup.PackStart (stopOnLocation);

				hboxLocation.PackStart (entryLocationFile, true);
				hboxLocation.PackStart (warningLocation);
				vboxLocation.PackEnd (hboxLocation);

				whenToTakeActionRadioGroup.PackStart (vboxLocation);
			}
			vbox.PackStart (whenToTakeActionRadioGroup);

			vbox.PackStart (new Label (GettextCatalog.GetString ("Advanced Conditions")) {
				Font = vbox.Font.WithWeight (FontWeight.Bold)
			});

			var vboxAdvancedConditions = new VBox {
				MarginLeft = 30
			};
			var hboxHitCount = new HBox ();
			hboxHitCount.PackStart (ignoreHitType, true);
			hboxHitCount.PackStart (ignoreHitCount);
			vboxAdvancedConditions.PackStart (hboxHitCount);

			vboxAdvancedConditions.PackStart (conditionalHitType);
			hboxCondition = new HBox ();
			hboxCondition.PackStart (entryConditionalExpression, true);
			hboxCondition.PackStart (warningCondition);
			vboxAdvancedConditions.PackStart (hboxCondition);
			vboxAdvancedConditions.PackEnd (conditionalExpressionTip);

			vbox.PackStart (vboxAdvancedConditions);


			Buttons.Add (new DialogButton (Command.Cancel));
			Buttons.Add (buttonOk);

			Content = vbox;

			if (IdeApp.Workbench != null) {
				Gtk.Widget parent = ((Gtk.Widget)Xwt.Toolkit.CurrentEngine.GetNativeWidget (vbox)).Parent;
				while (parent != null && !(parent is Gtk.Window))
					parent = parent.Parent;
				if (parent is Gtk.Window)
					((Gtk.Window)parent).TransientFor = IdeApp.Workbench.RootWindow;
			}

			OnUpdateControls (null, null);
		}
		protected override void Dispose (bool disposing)
		{
			CompletionWindowManager.WindowShown -= HandleCompletionWindowShown;
			CompletionWindowManager.WindowClosed -= HandleCompletionWindowClosed;
			base.Dispose (disposing);
		}
	}
}