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

MacDebuggerTooltipWindow.cs « QuickInfo « MonoDevelop.Debugger.VSTextView « MonoDevelop.Debugger « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de0d95a703bf5bc88139c03d4f94e8817341bd70 (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
//
// MacDebuggerTooltipWindow.cs
//
// Author:
//       Jeffrey Stedfast <jestedfa@microsoft.com>
//
// Copyright (c) 2019 Microsoft Corp.
//
// 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 AppKit;

using Mono.Debugging.Client;

namespace MonoDevelop.Debugger
{
	sealed class MacDebuggerTooltipWindow : NSPopover
	{
		readonly ObjectValueTreeViewController controller;
		readonly NSLayoutConstraint heightConstraint;
		readonly NSLayoutConstraint widthConstraint;
		readonly MacObjectValueTreeView treeView;
		readonly NSScrollView scrollView;
		bool disposed;

		public MacDebuggerTooltipWindow (PinnedWatchLocation location, StackFrame frame, ObjectValue value, PinnedWatch watch)
		{
			Animates = false;
			Behavior = NSPopoverBehavior.Semitransient;

			controller = new ObjectValueTreeViewController ();
			controller.SetStackFrame (frame);
			controller.AllowEditing = true;
			controller.PinnedWatch = watch;
			controller.PinnedWatchLocation = location;

			treeView = controller.GetMacControl (ObjectValueTreeViewFlags.TooltipFlags);
			treeView.NodePinned += OnPinStatusChanged;
			treeView.StartEditing += OnStartEditing;
			treeView.EndEditing += OnEndEditing;
			controller.AddValue (value);

			scrollView = new NSScrollView {
				HasVerticalScroller = true,
				AutohidesScrollers = true,
				DocumentView = treeView,
				Frame = treeView.Frame
			};

			ContentViewController = new NSViewController {
				View = scrollView
			};

			widthConstraint = scrollView.WidthAnchor.ConstraintEqualToConstant (treeView.Frame.Width);
			widthConstraint.Active = true;

			heightConstraint = scrollView.HeightAnchor.ConstraintEqualToConstant (treeView.Frame.Height);
			heightConstraint.Active = true;

			treeView.Resized += OnTreeViewResized;
		}

		public void Expand ()
		{
			treeView.ExpandItem (treeView.ItemAtRow (0), false);
		}

		public DebuggerSession GetDebuggerSession ()
		{
			return controller.GetStackFrame ()?.DebuggerSession;
		}

		static nfloat GetMaxHeight (NSWindow window)
		{
			var visibleFrame = window.Screen.VisibleFrame;

			// Note: You would think that we could make use of the full VisualFrame height,
			// but macOS will not actually make our tooltip window that large no matter
			// what.
			//
			// The downside of *trying* to use the full VisualFrame height is that the
			// scrollView will think that it is that tall when it in fact is not, thereby
			// making it impossible to scroll all the way to the top (and/or, potentially,
			// the bottom).
			//
			// On my machine, the VisualFrame height is 972 (Frame height is 1050 with a
			// menubar 23 pixels tall and a dock that is 55 pixels tall).
			//
			// macOS does not seem to allow the tooltip window to get larger than 943 pixels
			// which is 29 pixels shorter than the VisualFrame height. Let's just round that
			// up to 30 pixels.

			return visibleFrame.Height - 30;
		}

		void OnTreeViewResized (object sender, EventArgs e)
		{
			var height = (treeView.RowHeight + treeView.IntercellSpacing.Height) * treeView.RowCount;
			var maxHeight = GetMaxHeight (treeView.Window);

			height = NMath.Min (height, maxHeight);

			widthConstraint.Constant = treeView.OptimalTooltipWidth;
			heightConstraint.Constant = height;
		}

		void OnPinStatusChanged (object sender, EventArgs args)
		{
			Close ();
		}

		void OnStartEditing (object sender, EventArgs args)
		{
			//Modal = true;
			//PresentViewControllerAsModalWindow (this);
		}

		void OnEndEditing (object sender, EventArgs args)
		{
			//Modal = false;
		}

		void PreviewWindowManager_WindowClosed (object sender, EventArgs e)
		{
			// When Preview window is closed we want to put focus(IsActive=true) back on DebugValueWindow
			// otherwise CommandManager will think IDE doesn't have any window Active/Focused and think
			// user switched to another app and DebugValueWindow will closed itself on "FocusOut" event
			//Present ();
		}

		protected override void Dispose (bool disposing)
		{
			if (disposing && !disposed) {
				//PreviewWindowManager.WindowClosed -= PreviewWindowManager_WindowClosed;
				treeView.Resized -= OnTreeViewResized;
				treeView.NodePinned -= OnPinStatusChanged;
				treeView.StartEditing -= OnStartEditing;
				treeView.EndEditing -= OnEndEditing;
				heightConstraint.Dispose ();
				widthConstraint.Dispose ();
			}

			base.Dispose (disposing);
		}
	}
}