-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettings.cs
More file actions
701 lines (632 loc) · 30.1 KB
/
Settings.cs
File metadata and controls
701 lines (632 loc) · 30.1 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Jupyter;
using R;
using SAS;
using Stata;
using StatTag.Core.Models;
using StatTag.Models;
namespace StatTag
{
public sealed partial class Settings : Form
{
private const string ExecutableFileFilter = "Application Executable|*.exe";
private const string LogFileFilter = "Log File|*.log";
private const string BlankValueLabelTemplate =
"Note: The current document is set to use [BLANK_VALUE] for missing values. Changes made here will affect new documents, but not the current document. The setting for the current document can be changed under \"Document Properties\".";
public Core.Models.UserSettings Properties { get; set; }
private LogManager Logger { get; set; }
private DocumentManager Manager { get; set; }
private bool StataAutomationEnabledOnEntry { get; set; }
private SystemDetails SystemInformation { get; set; }
/// <summary>
/// If set when the dialog closes, this signals that a configuration change took place and
/// that StatTag should refresh the system information cache.
/// </summary>
public bool RefreshSystemInformation { get; private set; }
public Settings(Core.Models.UserSettings properties, DocumentManager manager, SystemDetails sysInfo)
{
AutoScaleMode = AutoScaleMode.None;
InitializeComponent();
Properties = properties;
Manager = manager;
SystemInformation = sysInfo;
MinimumSize = Size;
Logger = (Manager != null && Manager.Logger != null) ? Manager.Logger : new LogManager();
UIUtility.SetDialogTitle(this);
RefreshSystemInformation = false;
tabSettings.AutoSize = true;
tabGeneral.AutoSize = true;
tabLogging.AutoSize = true;
tabStata.AutoSize = true;
StataAutomationEnabledOnEntry = Stata.StataAutomation.IsAutomationEnabled();
chkStataAutomation.Checked = StataAutomationEnabledOnEntry;
UpdateStataSettingsUI();
UpdateJupyterSettingsUI(SystemInformation.RSupport);
}
private void cmdStataLocation_Click(object sender, EventArgs e)
{
var stataPath = UIUtility.GetOpenFileName(ExecutableFileFilter);
if (!string.IsNullOrWhiteSpace(stataPath))
{
txtStataLocation.Text = stataPath;
}
}
private void Settings_Load(object sender, EventArgs e)
{
txtStataLocation.Text = Properties.StataLocation;
chkEnableLogging.Checked = Properties.EnableLogging;
txtLogLocation.Text = Properties.LogLocation;
chkRunCodeOnOpen.Checked = Properties.RunCodeOnOpen;
txtMaxLogSize.Value = ((int)(Properties.GetValueInRange(Properties.MaxLogFileSize,
Core.Models.UserSettings.MaxLogFileSizeMin, Core.Models.UserSettings.MaxLogFileSizeMax,
Core.Models.UserSettings.MaxLogFileSizeDefault) / (Constants.BytesToMegabytesConversion * 1.0)));
txtMaxLogFiles.Value = Properties.GetValueInRange(Properties.MaxLogFiles,
Core.Models.UserSettings.MaxLogFilesMin, Core.Models.UserSettings.MaxLogFilesMax,
Core.Models.UserSettings.MaxLogFilesDefault);
missingValueSettings1.SetMissingValuesSelection(Properties.RepresentMissingValues);
missingValueSettings1.SetCustomMissingValueString(Properties.CustomMissingValue);
missingValueSettings1.ValueChanged += missingValueSettings_Changed;
UpdateLoggingControls();
UpdateMissingValueControls();
}
private void missingValueSettings_Changed(object sender, EventArgs e)
{
UpdateMissingValueControls();
}
private void UpdateMissingValueControls()
{
var documentMetadata = Manager.LoadMetadataFromCurrentDocument(false);
var customMissingValue = missingValueSettings1.GetCustomMissingValueString();
var representMissingValues = missingValueSettings1.GetMissingValuesSelection();
lblEmptyValueWarning.Visible = false;
if (documentMetadata != null && (!representMissingValues.Equals(documentMetadata.RepresentMissingValues)
|| (representMissingValues.Equals(Constants.MissingValueOption.CustomValue) && !customMissingValue.Equals(documentMetadata.CustomMissingValue))))
{
lblEmptyValueWarning.Text = BlankValueLabelTemplate.Replace("[BLANK_VALUE]", documentMetadata.GetMissingValueReplacementAsString());
lblEmptyValueWarning.Visible = true;
}
}
/// <summary>
/// Utility method to confirm that the Stata EXE path provided by the user is valid. If not,
/// inform the user of this.
/// </summary>
/// <returns>true if the file exists, or false otherwise</returns>
private bool CheckStataFilePath()
{
if (File.Exists(txtStataLocation.Text))
{
return true;
}
MessageBox.Show(this,
string.Format("The Stata executable could not be found at {0}.", txtStataLocation.Text),
UIUtility.GetAddInName(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
private bool EnableStataAutomation()
{
try
{
if (!CheckStataFilePath())
{
return false;
}
Cursor = Cursors.WaitCursor;
// We are going to first try to unregister the automation API, if it was set up.
// If this fails, we don't show an error message and will just move on trying to enable
// automation.
Stata.StataAutomation.UnregisterAutomationAPI(txtStataLocation.Text);
if (!Stata.StataAutomation.RegisterAutomationAPI(txtStataLocation.Text))
{
ShowStataCommandError("enable");
return false;
}
ShowStataCommandSuccess("enabled");
}
catch (Exception)
{
return false;
}
finally
{
Cursor = Cursors.Default;
}
RefreshSystemInformation = true;
return true;
}
private bool DisableStataAutomation()
{
try
{
if (!CheckStataFilePath())
{
return false;
}
if (DialogResult.Yes !=
MessageBox.Show(this,
"***WARNING: Disabling Stata Automation will reset your Stata user preferences.\r\n\r\nAlso, if you disable Stata Automation, StatTag will no longer work with Stata results.\r\n\r\nAre you sure you want to proceed?",
UIUtility.GetAddInName(), MessageBoxButtons.YesNo))
{
return false;
}
Cursor = Cursors.WaitCursor;
if (!Stata.StataAutomation.UnregisterAutomationAPI(txtStataLocation.Text))
{
ShowStataCommandError("disable");
return false;
}
ShowStataCommandSuccess("disabled");
}
finally
{
Cursor = Cursors.Default;
}
RefreshSystemInformation = true;
return true;
}
private void ShowStataCommandError(string action)
{
Cursor = Cursors.Default;
MessageBox.Show(
string.Format(
"There was an error trying to {0} the Stata Automation API.\r\nMore information about Stata Automation can be found at: http://www.stata.com/automation",
action), UIUtility.GetAddInName(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private void ShowStataCommandSuccess(string action)
{
Cursor = Cursors.Default;
MessageBox.Show(
string.Format(
"The Stata Automation API has been successfully {0}.",
action), UIUtility.GetAddInName());
}
private void cmdOK_Click(object sender, EventArgs e)
{
// If the Stata location has changed, and the user clicked 'OK' on this dialog, we're going to assume they
// want to enable the Stata automation API, or disable it if they unchecked the automation box.
if (!HandleStataAutomationAPIChanges())
{
DialogResult = DialogResult.None;
return;
}
Properties.StataLocation = txtStataLocation.Text;
Properties.EnableLogging = chkEnableLogging.Checked;
Properties.LogLocation = txtLogLocation.Text;
Properties.RunCodeOnOpen = chkRunCodeOnOpen.Checked;
Properties.MaxLogFileSize = ((uint)(txtMaxLogSize.Value * Constants.BytesToMegabytesConversion));
Properties.MaxLogFiles = (uint)txtMaxLogFiles.Value;
Properties.CustomMissingValue = missingValueSettings1.GetCustomMissingValueString();
Properties.RepresentMissingValues = missingValueSettings1.GetMissingValuesSelection();
if (Properties.EnableLogging && !Logger.IsValidLogPath(Properties.LogLocation))
{
UIUtility.WarningMessageBox("The debug file you have selected appears to be invalid, or you do not have rights to access it.\r\nPlease select a valid path for the debug file, or disable debugging.", null);
DialogResult = DialogResult.None;
}
}
private bool HandleStataAutomationAPIChanges()
{
// If the Stata location is empty, there's really nothing we can do. We're just going
// to accept the change and proceed. This will avoid warning the user that the file
// location "" (blank string) couldn't be found.
if (string.IsNullOrWhiteSpace(txtStataLocation.Text))
{
return true;
}
// If there was a change in the file location, and automation is still enabled, we
// need to handle unregistering and re-registering
if (chkStataAutomation.Checked && !string.Equals(Properties.StataLocation, txtStataLocation.Text))
{
return EnableStataAutomation();
}
else if (chkStataAutomation.Checked != StataAutomationEnabledOnEntry)
{
if (chkStataAutomation.Checked)
{
return EnableStataAutomation();
}
else
{
return DisableStataAutomation();
}
}
// No changes, so everything is fine.
return true;
}
private void chkEnableLogging_CheckedChanged(object sender, EventArgs e)
{
UpdateLoggingControls();
}
private void UpdateLoggingControls()
{
bool enableControls = chkEnableLogging.Checked;
cmdLogLocation.Enabled = enableControls;
txtLogLocation.Enabled = enableControls;
txtMaxLogFiles.Enabled = enableControls;
txtMaxLogSize.Enabled = enableControls;
}
private void cmdLogLocation_Click(object sender, EventArgs e)
{
var logPath = UIUtility.GetSaveFileName(LogFileFilter);
if (!string.IsNullOrWhiteSpace(logPath))
{
txtLogLocation.Text = logPath;
}
}
private void txtLogLocation_TextChanged(object sender, EventArgs e)
{
string logFilePath = txtLogLocation.Text;
if (string.IsNullOrWhiteSpace(logFilePath))
{
lblLogWarning.Text = "Please select or enter a file path";
lblLogWarning.Visible = true;
}
else
{
lblLogWarning.Visible = false;
}
}
private void chkStataAutomation_CheckedChanged(object sender, EventArgs e)
{
UpdateStataSettingsUI();
}
private void UpdateStataSettingsUI()
{
var enabled = chkStataAutomation.Checked;
txtStataLocation.Enabled = enabled;
cmdStataLocation.Enabled = enabled;
}
private void UpdateRSettingsUI(string rPath)
{
var supported = !(string.IsNullOrWhiteSpace(rPath));
lblRSupportStatus.Text = supported ? rPath : "R is not installed or selected R was not found";
lblRSupportStatus.ForeColor = supported ? Color.Black : Color.Red;
}
private void UpdateJupyterSettingsUI(bool supported)
{
lblRJupyterStatus.Text = supported ? "Enabled" : "Not detected";
lblRJupyterStatus.ForeColor = supported ? Color.Green : Color.Red;
}
/// <summary>
/// Utility method to detect and confirm an R installation.
/// </summary>
/// <returns>If R is found, it returns the base R path. If it is not found, this returns a blank string.</returns>
private string DetectRInstallation(bool writeLog)
{
try
{
if (writeLog)
{
LogRStatusAndLogger("Locating R...");
}
// If the user has selected a version of R, return that. Note that we are (for now)
// explicitly ignoring any additional checks that the path exists, like we do with
// the system auto-detect of R.
if (string.Equals(Properties.RDetection, Constants.RDetectionOption.Selected))
{
if (writeLog)
{
LogRStatusAndLogger("Using user-selected R");
}
if (Directory.Exists(Properties.RLocation))
{
if (writeLog)
{
LogRStatusAndLogger(string.Format("R path found: {0}", Properties.RLocation));
}
return Properties.RLocation;
}
else
{
if (writeLog)
{
LogRStatusAndLogger(string.Format("Selected R path could not be found: {0}", Properties.RLocation));
LogRStatusFailure();
}
return string.Empty;
}
}
var rPath = RAutomation.DetectRPath();
if (string.IsNullOrWhiteSpace(rPath))
{
if (writeLog)
{
LogRStatusAndLogger("Unable to locate an R installation using the registry");
LogRStatusFailure();
}
return string.Empty;
}
else if (!Directory.Exists(rPath))
{
if (writeLog)
{
LogRStatusAndLogger(string.Format("R path in registry but could not be found: {0}", rPath));
LogRStatusFailure();
}
return string.Empty;
}
else if (writeLog)
{
LogRStatusAndLogger(string.Format("R path found: {0}", rPath));
}
var rExePath = Path.Combine(rPath, "R.exe");
if (!File.Exists(rExePath))
{
if (writeLog)
{
LogRStatusAndLogger(string.Format("Could not find R.exe at {0}", rExePath));
LogRStatusFailure();
}
return string.Empty;
}
return rPath;
}
catch (Exception exc)
{
if (writeLog)
{
LogRStatusAndLogger(exc.Message);
LogRStatusFailure();
}
return string.Empty;
}
}
private void cmdInstallRSupport_Click(object sender, EventArgs e)
{
try
{
txtRSupportProgress.Text = string.Empty;
if (SystemInformation.RSupport)
{
var existingRResponse = MessageBox.Show("Your system already appears to be set up with R support for StatTag. You can attempt to re-install R support if you are having problems getting StatTag to execute R code.\r\n\r\nDo you wish to continue?",
UIUtility.GetAddInName(), MessageBoxButtons.YesNoCancel);
if (DialogResult.Yes != existingRResponse)
{
LogRStatusAndLogger("User cancelled setting up IRkernel");
return;
}
}
Logger.WriteMessage("Beginning installation of R support");
LogRStatusAndLogger("Proceeding with IRkernel setup.");
var rPath = DetectRInstallation(true);
if (string.IsNullOrWhiteSpace(rPath))
{
return;
}
rPath = Path.Combine(rPath, "R.exe");
if (!File.Exists(rPath))
{
LogRStatusAndLogger(string.Format("Could not find R.exe at {0}", rPath));
LogRStatusFailure();
return;
}
// If the user already has R support, they will have answered "Yes" above to proceeding. We don't need to bother
// them again with another confirmation.
if (!SystemInformation.RSupport)
{
var result = MessageBox.Show("StatTag will attempt to install and configure the IRkernel package in R. This will make changes to your R setup.\r\n\r\nDo you wish to continue?",
UIUtility.GetAddInName(), MessageBoxButtons.YesNoCancel);
if (DialogResult.Yes != result)
{
LogRStatusAndLogger("User cancelled setting up IRkernel");
return;
}
}
this.Cursor = Cursors.WaitCursor;
LogRStatusAndLogger("Attempting to install IRkernel...");
var libPathResult = JupyterAutomation.RunCommand(rPath, "-q -e \".libPaths()\"");
if (libPathResult.Result)
{
var libPaths = RAutomation.GetAccessibleLibPaths(libPathResult.Details);
if (libPaths.Length == 0)
{
LogRStatusAndLogger("Could not find any available R library paths...");
var libPath = RAutomation.GetUserLibPath();
// It's possible that the libPath exists but we couldn't detect it in R. If that's the case, we want
// to skip all of the setup steps, since the directory is there.
if (!string.IsNullOrWhiteSpace(libPath))
{
if (!Directory.Exists(libPath))
{
var result = MessageBox.Show(
string.Format("StatTag is unable to find an R library directory to install the IRkernel package. We can attempt to create one at {0}\r\n\r\nThis will create the directory, which R can use for other packages. If you don't want to create the directory, installation will proceed but may fail.\r\n\r\nDo you wish to create {0}?", libPath),
UIUtility.GetAddInName(), MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
LogRStatusAndLogger("Attempting to create " + libPath);
try
{
Directory.CreateDirectory(libPath);
}
catch (Exception exc)
{
LogRStatusAndLogger("Failed to create user libPath: " + exc.Message);
}
LogRStatusAndLogger("Created user libPath");
var libPathRegistrationResult = JupyterAutomation.RunCommand(rPath, "-q -e \".libPaths(c('" + libPath.Replace("\\", "/") + "', .libPaths()))\"");
if (libPathRegistrationResult.Result)
{
LogRStatusAndLogger("Registered user libPath");
}
else
{
LogRStatusAndLogger("Failed to register libPath: " + libPathRegistrationResult.Details);
}
}
else
{
LogRStatusAndLogger("Not creating " + libPath);
}
}
else
{
LogRStatusAndLogger("User libPath already exists: " + libPath);
}
}
else
{
LogRStatusAndLogger("Unable to find a valid user libPath");
}
}
}
else
{
LogRStatusAndLogger("Unable to determine existing libPaths:");
LogRStatusAndLogger(libPathResult.Details);
LogRStatusAndLogger("Proceeding with IRkernel installation command");
}
var irKernelResult = JupyterAutomation.RunCommand(rPath, "-q -e \"install.packages('IRkernel', repos = 'https://cloud.r-project.org')\"");
if (irKernelResult.Result)
{
LogRStatusAndLogger("Successfully installed (or confirmed installation of) IRkernel");
LogRStatusAndLogger(irKernelResult.Details);
}
else
{
LogRStatusAndLogger("Failed to install IRkernel. Please see the StatTag User Guide for more instructions on how to set up R support.");
LogRStatusAndLogger(irKernelResult.Details);
LogRStatusFailure();
return;
}
LogRStatusAndLogger("Detecting Jupyter...");
string embeddedJupyterExpandedPaths = null;
string embeddedJupyterPath = null;
var jupyterStatus = JupyterAutomation.DetectJupyter();
if (jupyterStatus.Result)
{
LogRStatusAndLogger("Found Jupyter: " + jupyterStatus.Details);
}
else
{
LogRStatusAndLogger("Did not find Jupyter. Using embedded Python environment.");
string embeddedJupyterSetupDetails = "";
embeddedJupyterPath = JupyterAutomation.SetupEmbeddedJupyter(ref embeddedJupyterSetupDetails);
if (string.IsNullOrWhiteSpace(embeddedJupyterPath))
{
LogRStatusAndLogger("Failed to use embedded Python environment. No available Python environment to use for IRkernel setup.");
if (!string.IsNullOrWhiteSpace(embeddedJupyterSetupDetails))
{
LogRStatusAndLogger(embeddedJupyterSetupDetails);
}
LogRStatusAndLogger("Failed to configure IRkernel. Please see the StatTag User Guide for more instructions on how to set up R support.");
return;
}
else
{
LogRStatusAndLogger(string.Format("Using embedded Python at: {0}", embeddedJupyterPath));
// The embeddedJupyterPath contains the base path for where the files exist. We need to expand this for adding
// to the PATH variable to include the base as well as the \Scripts subfolder.
embeddedJupyterExpandedPaths = string.Format("{0};{0}\\Scripts", embeddedJupyterPath);
}
}
// If we are using embedded Python, we need to install Jupyter libraries (just the minimum) in order
// to have support for all Jupyter-related commands.
if (!string.IsNullOrWhiteSpace(embeddedJupyterPath))
{
LogRStatusAndLogger("Attempting to install Jupyter support...");
var jupyterInstallResult = JupyterAutomation.RunCommand(
Path.Combine(embeddedJupyterPath, "python.exe"),
"-m pip install jupyter-core jupyter-client",
embeddedJupyterExpandedPaths);
if (!jupyterInstallResult.Result)
{
LogRStatusAndLogger("Failed to install Jupyter core libraries");
LogRStatusAndLogger(string.Format("Error: {0}", jupyterInstallResult.Details));
JupyterAutomation.RemoveEmbeddedJupyter(embeddedJupyterPath);
LogRStatusFailure();
return;
}
else
{
LogRStatusAndLogger("Successfully installed Jupyter infrastructure");
}
}
LogRStatusAndLogger("Attempting to configure IRkernel...");
var configResult = JupyterAutomation.RunCommand(rPath, "-q -e \"IRkernel::installspec()\"", embeddedJupyterExpandedPaths);
if (configResult.Result)
{
LogRStatusAndLogger("Successfully configured IRkernel");
UpdateJupyterSettingsUI(true);
RefreshSystemInformation = true;
}
else
{
LogRStatusAndLogger("Failed to configure IRkernel. Please see the StatTag User Guide for more instructions on how to set up R support.");
LogRStatusAndLogger(configResult.Details);
LogRStatusFailure();
}
// If we used a temporary Jupyter/Python environment to do this, clean it up.
if (!string.IsNullOrWhiteSpace(embeddedJupyterPath))
{
JupyterAutomation.RemoveEmbeddedJupyter(embeddedJupyterPath);
}
}
finally
{
this.Cursor = Cursors.Default;
}
}
/// <summary>
/// Utility function to write a final "failed" message during R support setup
/// </summary>
private void LogRStatusFailure()
{
LogRStatusAndLogger("\r\n*** SETUP FAILED ***");
}
/// <summary>
/// Utility function to log the same text both to the dialog text field, as well as the log (if enabled)
/// </summary>
/// <param name="text"></param>
private void LogRStatusAndLogger(string text)
{
txtRSupportProgress.Text += text + "\r\n";
txtRSupportProgress.SelectionStart = txtRSupportProgress.Text.Length;
txtRSupportProgress.ScrollToCaret();
this.Update();
Logger.WriteMessage(text);
}
private void cmdSelectR_Click(object sender, EventArgs e)
{
var dialog = new RVersion(Properties);
if (dialog.ShowDialog() == DialogResult.OK)
{
// Detect if the settings changed. If so, then we will trigger reloading
// the settings. Otherwise if it's the same we will leave the settings
// dialog the way it was.
var reloadR = dialog.Properties.RSettingsChanged(Properties);
Properties.RDetection = dialog.Properties.RDetection;
Properties.RLocation = dialog.Properties.RLocation;
Properties.RCustomPath = dialog.Properties.RCustomPath;
if (Manager.SettingsManager != null)
{
// Ensure we are only saving the R-related settings. We don't want to include any interim
// other settings that may get cancelled from being saved.
Manager.SettingsManager.Settings.RDetection = Properties.RDetection;
Manager.SettingsManager.Settings.RLocation = Properties.RLocation;
Manager.SettingsManager.Settings.RCustomPath = Properties.RCustomPath;
Manager.SettingsManager.Save();
}
if (Properties.RDetection.Equals(Constants.RDetectionOption.System))
{
UpdateRSettingsUI(RAutomation.DetectRPath());
}
else
{
UpdateRSettingsUI(Properties.RLocation);
}
if (reloadR)
{
RefreshSystemInformation = true;
UpdateJupyterSettingsUI(false);
}
}
}
}
}