~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ErrorService.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Windows;
 
6
using ICSharpCode.WpfDesign.Designer.Controls;
 
7
 
 
8
namespace ICSharpCode.WpfDesign.Designer.Services
 
9
{
 
10
        sealed class DefaultErrorService : IErrorService
 
11
        {
 
12
                sealed class AttachedErrorBalloon : ErrorBalloon
 
13
                {
 
14
                        FrameworkElement attachTo;
 
15
                        
 
16
                        public AttachedErrorBalloon(FrameworkElement attachTo, UIElement errorElement)
 
17
                        {
 
18
                                this.attachTo = attachTo;
 
19
                                this.Content = errorElement;
 
20
                        }
 
21
                        
 
22
                        internal void AttachEvents()
 
23
                        {
 
24
                                attachTo.Unloaded += OnCloseEvent;
 
25
                                attachTo.PreviewKeyDown += OnCloseEvent;
 
26
                                attachTo.PreviewMouseDown += OnCloseEvent;
 
27
                                attachTo.LostFocus += OnCloseEvent;
 
28
                        }
 
29
                        
 
30
                        void OnCloseEvent(object sender, EventArgs e)
 
31
                        {
 
32
                                this.Close();
 
33
                        }
 
34
                        
 
35
                        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
 
36
                        {
 
37
                                attachTo.Unloaded -= OnCloseEvent;
 
38
                                attachTo.PreviewKeyDown -= OnCloseEvent;
 
39
                                attachTo.PreviewMouseDown -= OnCloseEvent;
 
40
                                attachTo.LostFocus -= OnCloseEvent;
 
41
                                base.OnClosing(e);
 
42
                        }
 
43
                        
 
44
                        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
 
45
                        {
 
46
                                base.OnMouseDown(e);
 
47
                                Close();
 
48
                        }
 
49
                }
 
50
                
 
51
                ServiceContainer services;
 
52
                
 
53
                public DefaultErrorService(DesignContext context)
 
54
                {
 
55
                        this.services = context.Services;
 
56
                }
 
57
                
 
58
                public void ShowErrorTooltip(FrameworkElement attachTo, UIElement errorElement)
 
59
                {
 
60
                        if (attachTo == null)
 
61
                                throw new ArgumentNullException("attachTo");
 
62
                        if (errorElement == null)
 
63
                                throw new ArgumentNullException("errorElement");
 
64
                        
 
65
                        AttachedErrorBalloon b = new AttachedErrorBalloon(attachTo, errorElement);
 
66
                        Point pos = attachTo.PointToScreen(new Point(0, attachTo.ActualHeight));
 
67
                        b.Left = pos.X;
 
68
                        b.Top = pos.Y - 8;
 
69
                        b.Focusable = false;
 
70
                        ITopLevelWindowService windowService = services.GetService<ITopLevelWindowService>();
 
71
                        ITopLevelWindow ownerWindow = (windowService != null) ? windowService.GetTopLevelWindow(attachTo) : null;
 
72
                        if (ownerWindow != null) {
 
73
                                ownerWindow.SetOwner(b);
 
74
                        }
 
75
                        b.Show();
 
76
                        
 
77
                        if (ownerWindow != null) {
 
78
                                ownerWindow.Activate();
 
79
                        }
 
80
                        
 
81
                        b.AttachEvents();
 
82
                }
 
83
        }
 
84
}