~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/DebugCommands.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
                SelectExceptions,
62
62
                ShowCurrentExecutionLine,
63
63
                AddTracepoint,
64
 
                AddWatch
 
64
                AddWatch,
 
65
                StopEvaluation
65
66
        }
66
67
 
67
68
        internal class DebugHandler: CommandHandler
68
69
        {
69
70
                protected override void Run ()
70
71
                {
71
 
                        if (DebuggingService.IsDebugging && !DebuggingService.IsRunning) {
 
72
                        if (DebuggingService.IsPaused) {
72
73
                                DebuggingService.Resume ();
73
74
                                return;
74
75
                        }
80
81
                        
81
82
                        if (!IdeApp.Preferences.BuildBeforeExecuting) {
82
83
                                if (IdeApp.Workspace.IsOpen) {
83
 
                                        CheckResult cr = CheckBeforeDebugging (IdeApp.Workspace);
 
84
                                        CheckResult cr = CheckBeforeDebugging (IdeApp.ProjectOperations.CurrentSelectedSolution);
84
85
                                        if (cr == DebugHandler.CheckResult.Cancel)
85
86
                                                return;
86
87
                                        if (cr == DebugHandler.CheckResult.Run) {
87
 
                                                ExecuteWorkspace ();
 
88
                                                ExecuteSolution (IdeApp.ProjectOperations.CurrentSelectedSolution);
88
89
                                                return;
89
90
                                        }
90
91
                                        // Else continue building
96
97
                        }
97
98
                        
98
99
                        if (IdeApp.Workspace.IsOpen) {
99
 
                                IAsyncOperation op = IdeApp.ProjectOperations.Build (IdeApp.Workspace);
 
100
                                Solution sol = IdeApp.ProjectOperations.CurrentSelectedSolution;
 
101
                                IAsyncOperation op = IdeApp.ProjectOperations.Build (sol);
100
102
                                op.Completed += delegate {
101
103
                                        if (op.SuccessWithWarnings && !IdeApp.Preferences.RunWithWarnings)
102
104
                                                return;
103
105
                                        if (op.Success)
104
 
                                                ExecuteWorkspace ();
 
106
                                                ExecuteSolution (sol);
105
107
                                };
106
108
                        } else {
107
109
                                Document doc = IdeApp.Workbench.ActiveDocument;
118
120
                        }
119
121
                }
120
122
 
121
 
                void ExecuteWorkspace ()
 
123
                void ExecuteSolution (Solution sol)
122
124
                {
123
 
                        if (IdeApp.ProjectOperations.CanDebug (IdeApp.Workspace))
124
 
                                IdeApp.ProjectOperations.Debug (IdeApp.Workspace);
 
125
                        if (IdeApp.ProjectOperations.CanDebug (sol))
 
126
                                IdeApp.ProjectOperations.Debug (sol);
125
127
                        else
126
 
                                IdeApp.ProjectOperations.Execute (IdeApp.Workspace);
 
128
                                IdeApp.ProjectOperations.Execute (sol);
127
129
                }
128
130
 
129
131
                void ExecuteDocument (Document doc)
136
138
                
137
139
                protected override void Update (CommandInfo info)
138
140
                {
139
 
                        if (DebuggingService.IsDebugging && !DebuggingService.IsRunning) {
 
141
                        if (DebuggingService.IsPaused) {
140
142
                                info.Enabled = true;
141
143
                                info.Text = GettextCatalog.GetString ("_Continue");
142
144
                                info.Description = GettextCatalog.GetString ("Continue the execution of the application");
151
153
                        }
152
154
 
153
155
                        if (IdeApp.Workspace.IsOpen) {
154
 
                                bool canExecute = IdeApp.ProjectOperations.CanDebug (IdeApp.Workspace) ||
155
 
                                         (!DebuggingService.IsDebuggingSupported && IdeApp.ProjectOperations.CanExecute (IdeApp.Workspace));
 
156
                                var sol = IdeApp.ProjectOperations.CurrentSelectedSolution;
 
157
                                bool canExecute = sol != null && (
 
158
                                        IdeApp.ProjectOperations.CanDebug (sol) ||
 
159
                                        (!DebuggingService.IsDebuggingSupported && IdeApp.ProjectOperations.CanExecute (sol))
 
160
                                );
156
161
 
157
 
                                info.Enabled = (IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted || !DebuggingService.IsDebuggingSupported) &&
158
 
                                        canExecute &&
159
 
                                        !(IdeApp.ProjectOperations.CurrentSelectedItem is Workspace);
 
162
                                info.Enabled = canExecute && (IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted || !DebuggingService.IsDebuggingSupported);
160
163
                        } else {
161
164
                                Document doc = IdeApp.Workbench.ActiveDocument;
162
165
                                info.Enabled = (doc != null && doc.IsBuildTarget) && (doc.CanRun () || doc.CanDebug ());
289
292
                
290
293
                protected override void Update (CommandInfo info)
291
294
                {
292
 
                        info.Enabled = DebuggingService.IsDebugging && !DebuggingService.IsRunning;
 
295
                        info.Enabled = DebuggingService.IsPaused;
293
296
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Stepping);
294
297
                }
295
298
        }
303
306
                
304
307
                protected override void Update (CommandInfo info)
305
308
                {
306
 
                        info.Enabled = DebuggingService.IsDebugging && !DebuggingService.IsRunning;
 
309
                        info.Enabled = DebuggingService.IsPaused;
307
310
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Stepping);
308
311
                }
309
312
        }
317
320
                
318
321
                protected override void Update (CommandInfo info)
319
322
                {
320
 
                        info.Enabled = DebuggingService.IsDebugging && !DebuggingService.IsRunning;
 
323
                        info.Enabled = DebuggingService.IsPaused;
321
324
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Stepping);
322
325
                }
323
326
        }
354
357
        {
355
358
                protected override void Run ()
356
359
                {
357
 
                        DebuggingService.Breakpoints.Toggle (
 
360
                        var bp = DebuggingService.Breakpoints.Toggle (
358
361
                            IdeApp.Workbench.ActiveDocument.FileName,
359
 
                            IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
362
                            IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
 
363
                        
 
364
                        // If the breakpoint could not be inserted in the caret location, move the caret
 
365
                        // to the real line of the breakpoint, so that if the Toggle command is run again,
 
366
                        // this breakpoint will be removed
 
367
                        if (bp != null && bp.Line != IdeApp.Workbench.ActiveDocument.Editor.Caret.Line)
 
368
                                IdeApp.Workbench.ActiveDocument.Editor.Caret.Line = bp.Line;
360
369
                }
361
370
                
362
371
                protected override void Update (CommandInfo info)
363
372
                {
364
373
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
365
374
                        info.Enabled = IdeApp.Workbench.ActiveDocument != null && 
366
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
375
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
367
376
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
368
377
                                        !DebuggingService.Breakpoints.IsReadOnly;
369
378
                }
375
384
                {
376
385
                        DebuggingService.ShowAddTracepointDialog (
377
386
                            IdeApp.Workbench.ActiveDocument.FileName,
378
 
                            IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
387
                            IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
379
388
                }
380
389
                
381
390
                protected override void Update (CommandInfo info)
382
391
                {
383
392
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Tracepoints);
384
393
                        info.Enabled = IdeApp.Workbench.ActiveDocument != null && 
385
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
394
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
386
395
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
387
396
                                        !DebuggingService.Breakpoints.IsReadOnly;
388
397
                }
394
403
                {
395
404
                        IEnumerable brs = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
396
405
                            IdeApp.Workbench.ActiveDocument.FileName,
397
 
                            IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
406
                            IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
398
407
                        
399
408
                        foreach (Breakpoint bp in brs)
400
409
                                bp.Enabled = !bp.Enabled;
404
413
                {
405
414
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
406
415
                        if (IdeApp.Workbench.ActiveDocument != null && 
407
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
416
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
408
417
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
409
418
                                !DebuggingService.Breakpoints.IsReadOnly) {
410
419
                                info.Enabled = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
411
420
                                IdeApp. Workbench.ActiveDocument.FileName,
412
 
                                IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine).Count > 0;
 
421
                                IdeApp.Workbench.ActiveDocument.Editor.Caret.Line).Count > 0;
413
422
                        }
414
423
                        else
415
424
                                info.Enabled = false;
450
459
                {
451
460
                        IEnumerable<Breakpoint> brs = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
452
461
                            IdeApp.Workbench.ActiveDocument.FileName,
453
 
                            IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
462
                            IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
454
463
                        
455
464
                        List<Breakpoint> list = new List<Breakpoint> (brs);
456
465
                        foreach (Breakpoint bp in list)
461
470
                {
462
471
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
463
472
                        if (IdeApp.Workbench.ActiveDocument != null && 
464
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
473
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
465
474
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
466
475
                                !DebuggingService.Breakpoints.IsReadOnly) {
467
476
                                info.Enabled = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
468
477
                                IdeApp. Workbench.ActiveDocument.FileName,
469
 
                                IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine).Count > 0;
 
478
                                IdeApp.Workbench.ActiveDocument.Editor.Caret.Line).Count > 0;
470
479
                        }
471
480
                        else
472
481
                                info.Enabled = false;
477
486
        {
478
487
                protected override void Run ()
479
488
                {
480
 
                        Breakpoint bp = new Breakpoint (IdeApp.Workbench.ActiveDocument.FileName, IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
489
                        Breakpoint bp = new Breakpoint (IdeApp.Workbench.ActiveDocument.FileName, IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
481
490
                        if (DebuggingService.ShowBreakpointProperties (bp, true))
482
491
                                DebuggingService.Breakpoints.Add (bp);
483
492
                }
486
495
                {
487
496
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
488
497
                        if (IdeApp.Workbench.ActiveDocument != null && 
489
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
498
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
490
499
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
491
500
                                !DebuggingService.Breakpoints.IsReadOnly) {
492
501
                                info.Enabled = true;
502
511
                {
503
512
                        IList<Breakpoint> brs = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
504
513
                            IdeApp.Workbench.ActiveDocument.FileName,
505
 
                            IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine);
 
514
                            IdeApp.Workbench.ActiveDocument.Editor.Caret.Line);
506
515
 
507
516
                        if (brs.Count > 0)
508
517
                                DebuggingService.ShowBreakpointProperties (brs [0], false);
512
521
                {
513
522
                        info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
514
523
                        if (IdeApp.Workbench.ActiveDocument != null && 
515
 
                                        IdeApp.Workbench.ActiveDocument.TextEditor != null &&
 
524
                                        IdeApp.Workbench.ActiveDocument.Editor != null &&
516
525
                                        IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
517
526
                                !DebuggingService.Breakpoints.IsReadOnly) {
518
527
                                info.Enabled = DebuggingService.Breakpoints.GetBreakpointsAtFileLine (
519
528
                                IdeApp. Workbench.ActiveDocument.FileName,
520
 
                                IdeApp.Workbench.ActiveDocument.TextEditor.CursorLine).Count > 0;
 
529
                                IdeApp.Workbench.ActiveDocument.Editor.Caret.Line).Count > 0;
521
530
                        }
522
531
                        else
523
532
                                info.Enabled = false;
560
569
                
561
570
                protected override void Update (CommandInfo info)
562
571
                {
563
 
                        info.Enabled = DebuggingService.IsDebugging && !DebuggingService.IsRunning;
 
572
                        info.Enabled = DebuggingService.IsPaused;
564
573
                        info.Visible = DebuggingService.IsDebuggingSupported;
565
574
                }
566
575
        }
 
576
        
 
577
        internal class StopEvaluationHandler : CommandHandler
 
578
        {
 
579
                protected override void Run ()
 
580
                {
 
581
                        DebuggingService.DebuggerSession.CancelAsyncEvaluations ();
 
582
                }
 
583
                
 
584
                protected override void Update (CommandInfo info)
 
585
                {
 
586
                        info.Visible = DebuggingService.IsDebugging && DebuggingService.IsPaused && DebuggingService.DebuggerSession.CanCancelAsyncEvaluations;
 
587
                }
 
588
        }
567
589
}