@@ -46,14 +46,21 @@ namespace MonoDevelop.Debugger
46
46
public class NoSourceView : DocumentController
47
47
{
48
48
readonly ScrollView scrollView = new ScrollView ( ) ;
49
- readonly XwtControl xwtControl ;
49
+ readonly XwtControl control ;
50
50
DebuggerSessionOptions options ;
51
+ Label manageOptionsLabel ;
52
+ CheckBox sourceLinkCheckbox ;
53
+ Button sourceLinkButton ;
54
+ Label sourceLinkLabel ;
55
+ Button disassemblyButton ;
56
+ Label disassemblyLabel ;
57
+ Button browseButton ;
51
58
StackFrame frame ;
52
59
bool downloading ;
53
60
54
61
public NoSourceView ( )
55
62
{
56
- xwtControl = new XwtControl ( scrollView ) ;
63
+ control = new XwtControl ( scrollView ) ;
57
64
}
58
65
59
66
public void Update ( DebuggerSessionOptions options , StackFrame frame , bool disassemblySupported )
@@ -87,28 +94,24 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
87
94
Spacing = 10 ,
88
95
} ;
89
96
90
- var label = new Label {
97
+ sourceLinkLabel = new Label {
91
98
Markup = GettextCatalog . GetString ( "External source code is available. Would you like to download {0} and view it?" , $ "<a href=\" clicked\" >{ fileName } </a>") ,
92
99
Name = "SourceLinkLabel"
93
100
} ;
94
- label . LinkClicked += DownloadSourceLink ;
101
+ sourceLinkLabel . LinkClicked += OnDownloadSourceClicked ;
95
102
96
- sourceLinkVbox . PackStart ( label ) ;
103
+ sourceLinkVbox . PackStart ( sourceLinkLabel ) ;
97
104
98
105
var sourceLinkHbox = new HBox {
99
106
Spacing = 10
100
107
} ;
101
108
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 ) ;
107
112
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 ) ;
112
115
113
116
sourceLinkVbox . PackStart ( sourceLinkHbox ) ;
114
117
@@ -120,17 +123,14 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
120
123
121
124
var buttonBox = new HBox ( ) ;
122
125
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 ) ;
126
129
127
130
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 ) ;
134
134
}
135
135
136
136
var hbox = new HBox {
@@ -141,16 +141,12 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
141
141
hbox . PackStart ( buttonBox ) ;
142
142
143
143
if ( IdeApp . ProjectOperations . CurrentSelectedSolution != null ) {
144
- var manageLookupsLabel = new Label {
144
+ manageOptionsLabel = new Label {
145
145
Markup = GettextCatalog . GetString ( "Manage the locations used to find source files in the {0}." , "<a href=\" clicked\" >" + GettextCatalog . GetString ( "Solution Options" ) + "</a>" ) ,
146
146
MarginLeft = 10
147
147
} ;
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 ) ;
154
150
}
155
151
156
152
vbox . PackStart ( hbox ) ;
@@ -163,14 +159,11 @@ Widget CreateContent (DebuggerSessionOptions options, StackFrame frame, bool dis
163
159
vbox . PackStart ( label ) ;
164
160
165
161
if ( disassemblySupported ) {
166
- var labelDisassembly = new Label {
162
+ disassemblyLabel = new Label {
167
163
Markup = GettextCatalog . GetString ( "View disassembly in the {0}" , "<a href=\" clicked\" >" + GettextCatalog . GetString ( "Disassembly Tab" ) + "</a>" )
168
164
} ;
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 ) ;
174
167
}
175
168
}
176
169
@@ -189,11 +182,25 @@ string GetFilename (string fileName)
189
182
return fileName ;
190
183
}
191
184
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 )
193
200
{
194
201
var sf = DebuggingService . CurrentFrame ;
195
202
if ( sf == null ) {
196
- LoggingService . LogWarning ( $ "CurrentFrame was null in { nameof ( OpenFindSourceFileDialog ) } ") ;
203
+ LoggingService . LogWarning ( $ "CurrentFrame was null in { nameof ( OnBrowseClicked ) } ") ;
197
204
return ;
198
205
}
199
206
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)
267
274
return doc ;
268
275
}
269
276
270
- async void DownloadSourceLink ( object sender , EventArgs e )
277
+ async void OnDownloadSourceClicked ( object sender , EventArgs e )
271
278
{
272
279
if ( downloading )
273
280
return ;
274
281
275
282
downloading = true ;
276
283
277
284
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 ) {
293
286
options . AutomaticSourceLinkDownload = AutomaticSourceDownload . Always ;
294
287
DebuggingService . SetUserOptions ( options ) ;
295
288
}
@@ -307,7 +300,29 @@ async void DownloadSourceLink (object sender, EventArgs e)
307
300
308
301
protected override Task < Control > OnGetViewControlAsync ( CancellationToken token , DocumentViewContent view )
309
302
{
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 ( ) ;
311
326
}
312
327
}
313
328
}
0 commit comments