Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 48eef9d

Browse files
committed
[Debugger] Updated SourceLink UI to match suggestions by @hbons
1 parent 1d3f691 commit 48eef9d

File tree

1 file changed

+113
-49
lines changed

1 file changed

+113
-49
lines changed

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/NoSourceView.cs

Lines changed: 113 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class NoSourceView : DocumentController
4949
readonly XwtControl xwtControl;
5050
DebuggerSessionOptions options;
5151
StackFrame frame;
52+
bool downloading;
5253

5354
public NoSourceView ()
5455
{
@@ -64,69 +65,116 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
6465
{
6566
var fileName = GetFilename (frame.SourceLocation?.FileName);
6667
this.options = options;
67-
68-
var box = new VBox ();
69-
box.Margin = 30;
70-
box.Spacing = 10;
71-
7268
this.frame = frame;
7369

70+
var vbox = new VBox {
71+
Spacing = 10,
72+
Margin = 30
73+
};
74+
7475
if (!string.IsNullOrEmpty (fileName)) {
7576
DocumentTitle = GettextCatalog.GetString ("Source Not Found");
76-
var headerLabel = new Label ();
77-
headerLabel.Markup = GettextCatalog.GetString ("{0} file not found", $"<b>{fileName}</b>");
78-
box.PackStart (headerLabel);
77+
var headerLabel = new Label {
78+
Markup = GettextCatalog.GetString ("{0} file not found", $"<b>{fileName}</b>")
79+
};
80+
headerLabel.Font = headerLabel.Font.WithScaledSize (2);
81+
vbox.PackStart (headerLabel);
7982

80-
var actionsBox = new HBox ();
83+
if (frame.SourceLocation?.SourceLink != null && options.AutomaticSourceLinkDownload == AutomaticSourceDownload.Ask) {
84+
var sourceLinkVbox = new VBox {
85+
MarginBottom = 20,
86+
MarginTop = 10,
87+
Spacing = 10,
88+
};
8189

82-
var buttonBrowseAndFind = new Button (GettextCatalog.GetString ("Browse and find {0}", fileName));
83-
buttonBrowseAndFind.Clicked += OpenFindSourceFileDialog;
84-
actionsBox.PackStart (buttonBrowseAndFind);
90+
var label = new Label {
91+
Markup = GettextCatalog.GetString ("External source code is available. Would you like to download {0} and view it?", $"<a href=\"clicked\">{fileName}</a>"),
92+
Name = "SourceLinkLabel"
93+
};
94+
label.LinkClicked += DownloadSourceLink;
8595

86-
if (frame.SourceLocation?.SourceLink != null && options.AutomaticSourceLinkDownload == AutomaticSourceDownload.Ask) {
87-
var button = new Button (GettextCatalog.GetString ("Download via Source Link"));
88-
button.Name = "SourceLinkButton";
96+
sourceLinkVbox.PackStart (label);
97+
98+
var sourceLinkHbox = new HBox {
99+
Spacing = 10
100+
};
101+
102+
var button = new Button (GettextCatalog.GetString ("Download {0}", fileName)) {
103+
Name = "SourceLinkButton"
104+
};
89105
button.Clicked += DownloadSourceLink;
90-
actionsBox.PackStart (button);
106+
sourceLinkHbox.PackStart (button);
107+
108+
var checkbox = new CheckBox (GettextCatalog.GetString ("Always download source code automatically")) {
109+
Name = "SourceLinkCheckbox"
110+
};
111+
sourceLinkHbox.PackStart (checkbox);
91112

92-
var checkbox = new CheckBox (GettextCatalog.GetString ("Always get source code automatically"));
93-
checkbox.Name = "SourceLinkCheckbox";
94-
actionsBox.PackStart (checkbox);
113+
sourceLinkVbox.PackStart (sourceLinkHbox);
114+
115+
vbox.PackStart (sourceLinkVbox);
116+
117+
var separator = new HSeparator ();
118+
vbox.PackStart (separator);
95119
}
96120

97-
box.PackStart (actionsBox);
121+
var buttonBox = new HBox ();
122+
123+
var buttonBrowse = new Button (GettextCatalog.GetString ("Browse…"));
124+
buttonBrowse.Clicked += OpenFindSourceFileDialog;
125+
buttonBox.PackStart (buttonBrowse);
126+
127+
if (disassemblySupported) {
128+
var buttonDisassembly = new Button (GettextCatalog.GetString ("Go to Disassembly"));
129+
buttonDisassembly.Clicked += (sender, e) => {
130+
DebuggingService.ShowDisassembly ();
131+
Document.Close (false).Ignore ();
132+
};
133+
buttonBox.PackStart (buttonDisassembly);
134+
}
135+
136+
var hbox = new HBox {
137+
MarginTop = 20,
138+
Spacing = 10
139+
};
140+
141+
hbox.PackStart (buttonBox);
98142

99143
if (IdeApp.ProjectOperations.CurrentSelectedSolution != null) {
100-
var manageLookupsLabel = new Label ();
101-
manageLookupsLabel.Markup = GettextCatalog.GetString ("Manage the locations used to find source files in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Solution Options") + "</a>");
144+
var manageLookupsLabel = new Label {
145+
Markup = GettextCatalog.GetString ("Manage the locations used to find source files in the {0}.", "<a href=\"clicked\">" + GettextCatalog.GetString ("Solution Options") + "</a>"),
146+
MarginLeft = 10
147+
};
102148
manageLookupsLabel.LinkClicked += (sender, e) => {
103149
if (IdeApp.ProjectOperations.CurrentSelectedSolution == null)
104150
return;
105151
IdeApp.ProjectOperations.ShowOptions (IdeApp.ProjectOperations.CurrentSelectedSolution, "DebugSourceFiles");
106152
};
107-
box.PackStart (manageLookupsLabel);
153+
hbox.PackStart (manageLookupsLabel);
108154
}
109-
headerLabel.Font = headerLabel.Font.WithScaledSize (2);
155+
156+
vbox.PackStart (hbox);
110157
} else {
111158
DocumentTitle = GettextCatalog.GetString ("Source Not Available");
112159
var headerLabel = new Label (GettextCatalog.GetString ("Source Not Available"));
113-
box.PackStart (headerLabel);
160+
vbox.PackStart (headerLabel);
114161
var label = new Label (GettextCatalog.GetString ("Source information is missing from the debug information for this module"));
115-
box.PackStart (label);
116162
headerLabel.Font = label.Font.WithScaledSize (2);
117-
}
163+
vbox.PackStart (label);
118164

119-
if (disassemblySupported) {
120-
var labelDisassembly = new Label ();
121-
labelDisassembly.Markup = GettextCatalog.GetString ("View disassembly in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Disassembly Tab") + "</a>");
122-
labelDisassembly.LinkClicked += (sender, e) => {
123-
DebuggingService.ShowDisassembly ();
124-
Document.Close (false).Ignore ();
125-
};
126-
box.PackStart (labelDisassembly);
165+
if (disassemblySupported) {
166+
var labelDisassembly = new Label {
167+
Markup = GettextCatalog.GetString ("View disassembly in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Disassembly Tab") + "</a>")
168+
};
169+
labelDisassembly.LinkClicked += (sender, e) => {
170+
DebuggingService.ShowDisassembly ();
171+
Document.Close (false).Ignore ();
172+
};
173+
vbox.PackStart (labelDisassembly);
174+
}
127175
}
128176

129-
return box;
177+
return vbox;
130178
}
131179

132180
string GetFilename (string fileName)
@@ -221,23 +269,39 @@ public static async Task<Document> DownloadAndOpenAsync (StackFrame frame)
221269

222270
async void DownloadSourceLink (object sender, EventArgs e)
223271
{
224-
var button = (Button) sender;
272+
if (downloading)
273+
return;
225274

226-
// don't allow the user to click the button again
227-
button.Sensitive = false;
275+
downloading = true;
228276

229-
var actionsBox = (HBox) button.Parent;
230-
var checkbox = actionsBox.Children.OfType<CheckBox> ().FirstOrDefault (x => x.Name == "SourceLinkCheckbox");
231-
if (checkbox != null && checkbox.Active) {
232-
options.AutomaticSourceLinkDownload = AutomaticSourceDownload.Always;
233-
DebuggingService.SetUserOptions (options);
234-
}
277+
try {
278+
var widget = (Widget) sender;
279+
HBox hbox = null;
280+
281+
switch (widget.Name) {
282+
case "SourceLinkLabel":
283+
var vbox = (VBox) widget.Parent;
284+
hbox = vbox.Children.OfType<HBox> ().FirstOrDefault ();
285+
break;
286+
case "SourceLinkButton":
287+
hbox = (HBox) widget.Parent;
288+
break;
289+
}
290+
291+
var checkbox = hbox?.Children.OfType<CheckBox> ().FirstOrDefault (x => x.Name == "SourceLinkCheckbox");
292+
if (checkbox != null && checkbox.Active) {
293+
options.AutomaticSourceLinkDownload = AutomaticSourceDownload.Always;
294+
DebuggingService.SetUserOptions (options);
295+
}
235296

236-
var doc = await DownloadAndOpenAsync (frame);
297+
var doc = await DownloadAndOpenAsync (frame);
237298

238-
if (doc != null) {
239-
// close the NoSourceView document tab
240-
await Document.Close (false);
299+
if (doc != null) {
300+
// close the NoSourceView document tab
301+
await Document.Close (false);
302+
}
303+
} finally {
304+
downloading = false;
241305
}
242306
}
243307

0 commit comments

Comments
 (0)