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

Commit f71636b

Browse files
committed
[Debugger] unsubscribe event handlers from the NoSource page
1 parent 48eef9d commit f71636b

File tree

1 file changed

+70
-55
lines changed

1 file changed

+70
-55
lines changed

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

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,21 @@ namespace MonoDevelop.Debugger
4646
public class NoSourceView : DocumentController
4747
{
4848
readonly ScrollView scrollView = new ScrollView ();
49-
readonly XwtControl xwtControl;
49+
readonly XwtControl control;
5050
DebuggerSessionOptions options;
51+
Label manageOptionsLabel;
52+
CheckBox sourceLinkCheckbox;
53+
Button sourceLinkButton;
54+
Label sourceLinkLabel;
55+
Button disassemblyButton;
56+
Label disassemblyLabel;
57+
Button browseButton;
5158
StackFrame frame;
5259
bool downloading;
5360

5461
public NoSourceView ()
5562
{
56-
xwtControl = new XwtControl (scrollView);
63+
control = new XwtControl (scrollView);
5764
}
5865

5966
public void Update (DebuggerSessionOptions options, StackFrame frame, bool disassemblySupported)
@@ -87,28 +94,24 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
8794
Spacing = 10,
8895
};
8996

90-
var label = new Label {
97+
sourceLinkLabel = new Label {
9198
Markup = GettextCatalog.GetString ("External source code is available. Would you like to download {0} and view it?", $"<a href=\"clicked\">{fileName}</a>"),
9299
Name = "SourceLinkLabel"
93100
};
94-
label.LinkClicked += DownloadSourceLink;
101+
sourceLinkLabel.LinkClicked += OnDownloadSourceClicked;
95102

96-
sourceLinkVbox.PackStart (label);
103+
sourceLinkVbox.PackStart (sourceLinkLabel);
97104

98105
var sourceLinkHbox = new HBox {
99106
Spacing = 10
100107
};
101108

102-
var button = new Button (GettextCatalog.GetString ("Download {0}", fileName)) {
103-
Name = "SourceLinkButton"
104-
};
105-
button.Clicked += DownloadSourceLink;
106-
sourceLinkHbox.PackStart (button);
109+
sourceLinkButton = new Button (GettextCatalog.GetString ("Download {0}", fileName));
110+
sourceLinkButton.Clicked += OnDownloadSourceClicked;
111+
sourceLinkHbox.PackStart (sourceLinkButton);
107112

108-
var checkbox = new CheckBox (GettextCatalog.GetString ("Always download source code automatically")) {
109-
Name = "SourceLinkCheckbox"
110-
};
111-
sourceLinkHbox.PackStart (checkbox);
113+
sourceLinkCheckbox = new CheckBox (GettextCatalog.GetString ("Always download source code automatically"));
114+
sourceLinkHbox.PackStart (sourceLinkCheckbox);
112115

113116
sourceLinkVbox.PackStart (sourceLinkHbox);
114117

@@ -120,17 +123,14 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
120123

121124
var buttonBox = new HBox ();
122125

123-
var buttonBrowse = new Button (GettextCatalog.GetString ("Browse…"));
124-
buttonBrowse.Clicked += OpenFindSourceFileDialog;
125-
buttonBox.PackStart (buttonBrowse);
126+
browseButton = new Button (GettextCatalog.GetString ("Browse…"));
127+
browseButton.Clicked += OnBrowseClicked;
128+
buttonBox.PackStart (browseButton);
126129

127130
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);
131+
disassemblyButton = new Button (GettextCatalog.GetString ("Go to Disassembly"));
132+
disassemblyButton.Clicked += OnGoToDisassemblyClicked;
133+
buttonBox.PackStart (disassemblyButton);
134134
}
135135

136136
var hbox = new HBox {
@@ -141,16 +141,12 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
141141
hbox.PackStart (buttonBox);
142142

143143
if (IdeApp.ProjectOperations.CurrentSelectedSolution != null) {
144-
var manageLookupsLabel = new Label {
144+
manageOptionsLabel = new Label {
145145
Markup = GettextCatalog.GetString ("Manage the locations used to find source files in the {0}.", "<a href=\"clicked\">" + GettextCatalog.GetString ("Solution Options") + "</a>"),
146146
MarginLeft = 10
147147
};
148-
manageLookupsLabel.LinkClicked += (sender, e) => {
149-
if (IdeApp.ProjectOperations.CurrentSelectedSolution == null)
150-
return;
151-
IdeApp.ProjectOperations.ShowOptions (IdeApp.ProjectOperations.CurrentSelectedSolution, "DebugSourceFiles");
152-
};
153-
hbox.PackStart (manageLookupsLabel);
148+
manageOptionsLabel.LinkClicked += OnManageSolutionOptionsClicked;
149+
hbox.PackStart (manageOptionsLabel);
154150
}
155151

156152
vbox.PackStart (hbox);
@@ -163,14 +159,11 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
163159
vbox.PackStart (label);
164160

165161
if (disassemblySupported) {
166-
var labelDisassembly = new Label {
162+
disassemblyLabel = new Label {
167163
Markup = GettextCatalog.GetString ("View disassembly in the {0}", "<a href=\"clicked\">" + GettextCatalog.GetString ("Disassembly Tab") + "</a>")
168164
};
169-
labelDisassembly.LinkClicked += (sender, e) => {
170-
DebuggingService.ShowDisassembly ();
171-
Document.Close (false).Ignore ();
172-
};
173-
vbox.PackStart (labelDisassembly);
165+
disassemblyLabel.LinkClicked += OnGoToDisassemblyClicked;
166+
vbox.PackStart (disassemblyLabel);
174167
}
175168
}
176169

@@ -189,11 +182,25 @@ string GetFilename (string fileName)
189182
return fileName;
190183
}
191184

192-
async void OpenFindSourceFileDialog (object sender, EventArgs e)
185+
void OnGoToDisassemblyClicked (object sender, EventArgs e)
186+
{
187+
DebuggingService.ShowDisassembly ();
188+
Document.Close (false).Ignore ();
189+
}
190+
191+
void OnManageSolutionOptionsClicked (object sender, EventArgs e)
192+
{
193+
if (IdeApp.ProjectOperations.CurrentSelectedSolution == null)
194+
return;
195+
196+
IdeApp.ProjectOperations.ShowOptions (IdeApp.ProjectOperations.CurrentSelectedSolution, "DebugSourceFiles");
197+
}
198+
199+
async void OnBrowseClicked (object sender, EventArgs e)
193200
{
194201
var sf = DebuggingService.CurrentFrame;
195202
if (sf == null) {
196-
LoggingService.LogWarning ($"CurrentFrame was null in {nameof (OpenFindSourceFileDialog)}");
203+
LoggingService.LogWarning ($"CurrentFrame was null in {nameof (OnBrowseClicked)}");
197204
return;
198205
}
199206
var dlg = new Ide.Gui.Dialogs.OpenFileDialog (GettextCatalog.GetString ("File to Open") + " " + sf.SourceLocation.FileName, FileChooserAction.Open) {
@@ -267,29 +274,15 @@ public static async Task<Document> DownloadAndOpenAsync (StackFrame frame)
267274
return doc;
268275
}
269276

270-
async void DownloadSourceLink (object sender, EventArgs e)
277+
async void OnDownloadSourceClicked (object sender, EventArgs e)
271278
{
272279
if (downloading)
273280
return;
274281

275282
downloading = true;
276283

277284
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) {
285+
if (sourceLinkCheckbox != null && sourceLinkCheckbox.Active) {
293286
options.AutomaticSourceLinkDownload = AutomaticSourceDownload.Always;
294287
DebuggingService.SetUserOptions (options);
295288
}
@@ -307,7 +300,29 @@ async void DownloadSourceLink (object sender, EventArgs e)
307300

308301
protected override Task<Control> OnGetViewControlAsync (CancellationToken token, DocumentViewContent view)
309302
{
310-
return Task.FromResult<Control> (xwtControl);
303+
return Task.FromResult<Control> (control);
304+
}
305+
306+
protected override void OnDispose ()
307+
{
308+
if (sourceLinkButton != null) {
309+
sourceLinkLabel.LinkClicked -= OnDownloadSourceClicked;
310+
sourceLinkButton.Clicked -= OnDownloadSourceClicked;
311+
}
312+
313+
if (browseButton != null)
314+
browseButton.Clicked -= OnBrowseClicked;
315+
316+
if (disassemblyButton != null)
317+
disassemblyButton.Clicked -= OnGoToDisassemblyClicked;
318+
319+
if (disassemblyLabel != null)
320+
disassemblyLabel.LinkClicked -= OnGoToDisassemblyClicked;
321+
322+
if (manageOptionsLabel != null)
323+
manageOptionsLabel.LinkClicked -= OnManageSolutionOptionsClicked;
324+
325+
base.OnDispose ();
311326
}
312327
}
313328
}

0 commit comments

Comments
 (0)