Browse Source

Fixed exception opening StyleCop options when StyleCop is not installed

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3597 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
fef66a43e6
  1. 205
      src/AddIns/Misc/SourceAnalysis/Src/AnalysisProjectOptionsPanel.cs

205
src/AddIns/Misc/SourceAnalysis/Src/AnalysisProjectOptionsPanel.cs

@ -14,116 +14,121 @@ using ICSharpCode.SharpDevelop.Gui.OptionPanels;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
namespace MattEverson.SourceAnalysis { namespace MattEverson.SourceAnalysis {
public class AnalysisProjectOptionsPanel : AbstractProjectOptionPanel { public class AnalysisProjectOptionsPanel : AbstractProjectOptionPanel {
public override void LoadPanelContents() { public override void LoadPanelContents() {
InitializeHelper(); InitializeHelper();
var masterSettingsFile = helper.GetProperty<string>("SourceAnalysisOverrideSettingsFile", "", true); var masterSettingsFile = helper.GetProperty<string>("SourceAnalysisOverrideSettingsFile", "", true);
if (masterSettingsFile.Length == 0) { if (masterSettingsFile.Length == 0) {
helper.SetProperty<string>("SourceAnalysisOverrideSettingsFile", helper.SetProperty<string>("SourceAnalysisOverrideSettingsFile",
StyleCopWrapper.GetMasterSettingsFile(), StyleCopWrapper.GetMasterSettingsFile(),
true, true,
PropertyStorageLocations.Base); PropertyStorageLocations.Base);
} }
AnalysisProjectOptions po = new AnalysisProjectOptions(); AnalysisProjectOptions po = new AnalysisProjectOptions();
po.Dock = DockStyle.Fill; po.Dock = DockStyle.Fill;
Controls.Add(po); Controls.Add(po);
ChooseStorageLocationButton btnEnable; ChooseStorageLocationButton btnEnable;
ChooseStorageLocationButton btnFileLocation; ChooseStorageLocationButton btnFileLocation;
btnEnable = helper.BindBoolean(po.EnableCheckBox, "RunSourceAnalysis", false).CreateLocationButton(po.EnableCheckBox); btnEnable = helper.BindBoolean(po.EnableCheckBox, "RunSourceAnalysis", false).CreateLocationButton(po.EnableCheckBox);
btnFileLocation = helper.BindString(po.SettingsFileTextBox, "SourceAnalysisOverrideSettingsFile", TextBoxEditMode.EditRawProperty).CreateLocationButton(po.SettingsFileTextBox); btnFileLocation = helper.BindString(po.SettingsFileTextBox, "SourceAnalysisOverrideSettingsFile", TextBoxEditMode.EditRawProperty).CreateLocationButton(po.SettingsFileTextBox);
ConfigurationGuiBinding binding = po.CreateBinding(); ConfigurationGuiBinding binding = po.CreateBinding();
binding.RegisterLocationButton(btnEnable); binding.RegisterLocationButton(btnEnable);
binding.RegisterLocationButton(btnFileLocation); binding.RegisterLocationButton(btnFileLocation);
helper.AddConfigurationSelector(this); helper.AddConfigurationSelector(this);
po.ModifyStyleCopSettingsButton.Click += ModifyStyleCopSettingsClick; po.ModifyStyleCopSettingsButton.Click += ModifyStyleCopSettingsClick;
} }
void ModifyStyleCopSettingsClick(object sender, EventArgs e) { void ModifyStyleCopSettingsClick(object sender, EventArgs e) {
var settingsFile = helper.GetProperty<string>("SourceAnalysisOverrideSettingsFile", "", true); var settingsFile = helper.GetProperty<string>("SourceAnalysisOverrideSettingsFile", "", true);
if (settingsFile == StyleCopWrapper.GetMasterSettingsFile()) { if (settingsFile == StyleCopWrapper.GetMasterSettingsFile()) {
if (ConfirmSwitchFromMaster()) { if (ConfirmSwitchFromMaster()) {
settingsFile = CopyFromMaster(); settingsFile = CopyFromMaster();
} }
} }
if (!System.IO.File.Exists(settingsFile)) { if (!System.IO.File.Exists(settingsFile)) {
if (ConfirmReplaceMissingFile()) { if (ConfirmReplaceMissingFile()) {
settingsFile = CopyFromMaster(); settingsFile = CopyFromMaster();
} }
else { else {
MessageService.ShowWarning("No settings file found to modify."); MessageService.ShowWarning("No settings file found to modify.");
return; return;
} }
} }
var executable = Path.Combine(StyleCopWrapper.FindStyleCopPath(), "StyleCopSettingsEditor.exe"); string styleCopPath = StyleCopWrapper.FindStyleCopPath();
var parameters = "\"" + settingsFile + "\""; string executable;
if (!File.Exists(executable)) { if (styleCopPath != null)
LoggingService.Debug("StyleCopSettingsEditor.exe: " + executable); executable = Path.Combine(styleCopPath, "StyleCopSettingsEditor.exe");
MessageService.ShowWarning("Unable to find the StyleCop Settings editor. Please specify the StyleCop location in Tools Options."); else
return; executable = null;
} string parameters = "\"" + settingsFile + "\"";
if (!File.Exists(executable)) {
using(Process p = Process.Start("\"" + executable + "\"", parameters)) { LoggingService.Debug("StyleCopSettingsEditor.exe: " + executable);
// No need to wait for the settings dialog to close - we can leave it open. MessageService.ShowWarning("Unable to find the StyleCop Settings editor. Please specify the StyleCop location in Tools Options.");
} return;
} }
using(Process p = Process.Start("\"" + executable + "\"", parameters)) {
// No need to wait for the settings dialog to close - we can leave it open.
}
}
private bool ConfirmReplaceMissingFile() { private bool ConfirmReplaceMissingFile() {
var result = MessageBox.Show("A settings file is not present. Would you like to copy the master into the " + var result = MessageBox.Show("A settings file is not present. Would you like to copy the master into the " +
"project folder?", "project folder?",
"Missing Settings File", "Missing Settings File",
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1 MessageBoxDefaultButton.Button1
); );
if (result == DialogResult.Yes) { if (result == DialogResult.Yes) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
private bool ConfirmSwitchFromMaster() private bool ConfirmSwitchFromMaster()
{ {
var result = MessageBox.Show("You are currently using the master settings file. Do you want to make a " var result = MessageBox.Show("You are currently using the master settings file. Do you want to make a "
+ "copy in the project folder instead?", + "copy in the project folder instead?",
"Using Master Settings File", "Using Master Settings File",
MessageBoxButtons.YesNo, MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1 MessageBoxDefaultButton.Button1
); );
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
return true; return true;
} }
else else
{ {
return false; return false;
} }
} }
private string CopyFromMaster() { private string CopyFromMaster() {
var newSettingsFile = helper.Project.Directory + "\\Settings.SourceAnalysis"; var newSettingsFile = helper.Project.Directory + "\\Settings.SourceAnalysis";
System.IO.File.Copy( System.IO.File.Copy(
StyleCopWrapper.GetMasterSettingsFile(), StyleCopWrapper.GetMasterSettingsFile(),
newSettingsFile, newSettingsFile,
true true
); );
helper.SetProperty<string>("SourceAnalysisOverrideSettingsFile", helper.SetProperty<string>("SourceAnalysisOverrideSettingsFile",
newSettingsFile, newSettingsFile,
true, true,
PropertyStorageLocations.Base PropertyStorageLocations.Base
); );
return newSettingsFile; return newSettingsFile;
} }
} }
} }

Loading…
Cancel
Save