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

NoSourceView.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: c2fbbfff1a87d81da067852d6035af09c9593e7f (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
//
// NoSourceView.cs
//
// Author:
//       David Karlaš <david.karlas@microsoft.com>
//
// Copyright (c) 2017 Microsoft Corporation
//
// 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 System.IO;
using MonoDevelop.Components;
using MonoDevelop.Core;
using MonoDevelop.Ide;
using MonoDevelop.Ide.Gui;
using Xwt;
using MonoDevelop.Ide.Gui.Documents;
using System.Threading;
using System.Threading.Tasks;

namespace MonoDevelop.Debugger
{
	public class NoSourceView : DocumentController
	{
		XwtControl xwtControl;
		ScrollView scrollView = new ScrollView ();
		public NoSourceView ()
		{
			xwtControl = new XwtControl (scrollView);
		}

		public void Update (bool disassemblyNotSupported)
		{
			scrollView.Content = CreateContent (disassemblyNotSupported);
		}

		Widget CreateContent (bool disassemblyNotSupported)
		{
			var fileName = GetFilename (DebuggingService.CurrentFrame?.SourceLocation?.FileName);
			var box = new VBox ();
			box.Margin = 30;
			box.Spacing = 10;
			if (!string.IsNullOrEmpty (fileName)) {
				DocumentTitle = GettextCatalog.GetString ("Source Not Found");
				var headerLabel = new Label ();
				headerLabel.Markup = GettextCatalog.GetString ("{0} file not found", $"<b>{fileName}</b>");
				box.PackStart (headerLabel);
				var actionsBox = new HBox ();
				var buttonBrowseAndFind = new Button (GettextCatalog.GetString ("Browse and find {0}", fileName));
				buttonBrowseAndFind.Clicked += OpenFindSourceFileDialog;
				actionsBox.PackStart (buttonBrowseAndFind);
				box.PackStart (actionsBox);
				if (IdeApp.ProjectOperations.CurrentSelectedSolution != null) {
					var manageLookupsLabel = new Label ();
					manageLookupsLabel.Markup = GettextCatalog.GetString ("Manage the locations used to find source files in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Solution Options") + "</a>");
					manageLookupsLabel.LinkClicked += (sender, e) => {
						if (IdeApp.ProjectOperations.CurrentSelectedSolution == null)
							return;
						IdeApp.ProjectOperations.ShowOptions (IdeApp.ProjectOperations.CurrentSelectedSolution, "DebugSourceFiles");
					};
					box.PackStart (manageLookupsLabel);
				}
				headerLabel.Font = headerLabel.Font.WithScaledSize (2);
			} else {
				DocumentTitle = GettextCatalog.GetString ("Source Not Available");
				var headerLabel = new Label (GettextCatalog.GetString ("Source Not Available"));
				box.PackStart (headerLabel);
				var label = new Label (GettextCatalog.GetString ("Source information is missing from the debug information for this module"));
				box.PackStart (label);
				headerLabel.Font = label.Font.WithScaledSize (2);
			}
			if (!disassemblyNotSupported) {
				var labelDisassembly = new Label ();
				labelDisassembly.Markup = GettextCatalog.GetString ("View disassembly in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Disassembly Tab") + "</a>");
				labelDisassembly.LinkClicked += (sender, e) => {
					DebuggingService.ShowDisassembly ();
					Document.Close (false).Ignore ();
				};
				box.PackStart (labelDisassembly);
			}
			return box;
		}

		string GetFilename (string fileName)
		{
			if (fileName == null)
				return null;
			var index = fileName.LastIndexOfAny (new char [] { '/', '\\' });
			if (index != -1)
				return fileName.Substring (index + 1);
			return fileName;
		}

		private async void OpenFindSourceFileDialog (object sender, EventArgs e)
		{
			var sf = DebuggingService.CurrentFrame;
			if (sf == null) {
				LoggingService.LogWarning ($"CurrentFrame was null in {nameof (OpenFindSourceFileDialog)}");
				return;
			}
			var dlg = new Ide.Gui.Dialogs.OpenFileDialog (GettextCatalog.GetString ("File to Open") + " " + sf.SourceLocation.FileName, FileChooserAction.Open) {
				TransientFor = IdeApp.Workbench.RootWindow,
				ShowEncodingSelector = true,
				ShowViewerSelector = true
			};
			dlg.DirectoryChangedHandler = (s, path) => {
				return SourceCodeLookup.TryDebugSourceFolders (sf.SourceLocation.FileName, sf.SourceLocation.FileHash, new string [] { path });
			};
			if (!dlg.Run ())
				return;
			var newFilePath = dlg.SelectedFile;
			try {
				if (File.Exists (newFilePath)) {
					var ignoreButton = new AlertButton (GettextCatalog.GetString ("Ignore"));
					if (SourceCodeLookup.CheckFileHash (newFilePath, sf.SourceLocation.FileHash) ||
						MessageService.AskQuestion (GettextCatalog.GetString ("File checksum doesn't match."), 1, ignoreButton, new AlertButton (GettextCatalog.GetString ("Cancel"))) == ignoreButton) {
						SourceCodeLookup.AddLoadedFile (newFilePath, sf.SourceLocation.FileName);
						sf.UpdateSourceFile (newFilePath);

						var doc = await IdeApp.Workbench.OpenDocument (newFilePath, null, sf.SourceLocation.Line, 1, OpenDocumentOptions.Debugger);
						if (doc != null) {
							await Document.Close (false);
						}
					}
				} else {
					MessageService.ShowWarning (GettextCatalog.GetString ("File not found."));
				}
			} catch (Exception) {
				MessageService.ShowWarning (GettextCatalog.GetString ("Error opening file."));
			}
		}

		protected override Task<Control> OnGetViewControlAsync (CancellationToken token, DocumentViewContent view)
		{
			return Task.FromResult<Control> (xwtControl);
		}
	}
}