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

Loading…
Cancel
Save