Skip to content

Commit

Permalink
Cleanup...
Browse files Browse the repository at this point in the history
  • Loading branch information
slavara committed Apr 13, 2016
1 parent f376e97 commit fa4a65e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 178 deletions.
2 changes: 1 addition & 1 deletion AntPanel/AntPanel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PlatformTarget>x86</PlatformTarget>
<OutputPath>..\..\..\..\FlashDevelop\Bin\Debug\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand Down
63 changes: 22 additions & 41 deletions AntPanel/PluginMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

namespace AntPanel
{
/// <summary>
/// </summary>
public class PluginMain : IPlugin
{
public readonly List<string> BuildFilesList = new List<string>();
Expand Down Expand Up @@ -87,8 +85,8 @@ public void Initialize()
public void Dispose() => SaveSettings();

/// <summary>
/// Handles the incoming events
/// </summary>
/// Adds the required event handlers
/// </summary>
public void AddEventHandlers() => EventManager.AddEventHandler(this, EventType.UIStarted | EventType.Command);

/// <summary>
Expand All @@ -102,7 +100,7 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)
DirectoryNode.OnDirectoryNodeRefresh += OnDirectoryNodeRefresh;
break;
case EventType.Command:
DataEvent da = (DataEvent)e;
var da = (DataEvent)e;
switch (da.Action)
{
case ProjectManagerEvents.Project:
Expand All @@ -121,51 +119,39 @@ public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)

#region Custom Public Methods

/// <summary>
/// </summary>
/// <param name="files"></param>
public void AddBuildFiles(IEnumerable<string> files)
{
foreach (string file in files.Where(file => !BuildFilesList.Contains(file)))
foreach (var file in files.Where(file => !BuildFilesList.Contains(file)))
BuildFilesList.Add(file);
SaveBuildFiles();
pluginUI.RefreshData();
}

/// <summary>
/// </summary>
/// <param name="file"></param>
public void RemoveBuildFile(string file)
{
if (BuildFilesList.Contains(file)) BuildFilesList.Remove(file);
SaveBuildFiles();
pluginUI.RefreshData();
}

/// <summary>
/// </summary>
/// <param name="file"></param>
/// <param name="target"></param>
public void RunTarget(string file, string target)
{
string antPath = ((Settings)Settings).AntPath;
string command = Path.Combine(Environment.SystemDirectory, "cmd.exe");
string arguments = "/c ";
var antPath = ((Settings)Settings).AntPath;
var command = PluginBase.MainForm.CommandPromptExecutable ?? Path.Combine(Environment.SystemDirectory, "cmd.exe");
var arguments = "/c ";
if (string.IsNullOrEmpty(antPath)) arguments += "ant";
else arguments += Path.Combine(Path.Combine(antPath, "bin"), "ant");
arguments += $" -buildfile \"{file}\" \"{target}\"";
PluginBase.MainForm.CallCommand("RunProcessCaptured", command + ";" + arguments);
PluginBase.MainForm.CallCommand("RunProcessCaptured", $"{command};{arguments}");
}

/// <summary>
/// </summary>
public void ReadBuildFiles()
{
BuildFilesList.Clear();
string folder = GetBuildFilesStorageFolder();
string fullName = Path.Combine(folder, StorageFileName);
var folder = GetBuildFilesStorageFolder();
var fullName = Path.Combine(folder, StorageFileName);
if (!File.Exists(fullName)) return;
StreamReader file = new StreamReader(fullName);
var file = new StreamReader(fullName);
string line;
while ((line = file.ReadLine()) != null)
if (!string.IsNullOrEmpty(line) && !BuildFilesList.Contains(line))
Expand All @@ -183,19 +169,19 @@ public void ReadBuildFiles()
void InitBasics()
{
pluginImage = PluginBase.MainForm.FindImage("486");
string dataPath = Path.Combine(PathHelper.DataDir, "AntPanel");
if (!Directory.Exists(dataPath)) Directory.CreateDirectory(dataPath);
settingFilename = Path.Combine(dataPath, "Settings.fdb");
var path = Path.Combine(PathHelper.DataDir, "AntPanel");
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
settingFilename = Path.Combine(path, "Settings.fdb");
}

/// <summary>
/// Creates a menu item for the plugin
/// </summary>
void CreateMenuItem()
{
ToolStripMenuItem menuItem = new ToolStripMenuItem("Ant Panel", pluginImage, OpenPanel);
var menuItem = new ToolStripMenuItem("Ant Panel", pluginImage, OpenPanel);
PluginBase.MainForm.RegisterShortcutItem("ViewMenu.ShowAntPanel", menuItem);
ToolStripMenuItem menu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu");
var menu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu");
menu.DropDownItems.Add(menuItem);
}

Expand Down Expand Up @@ -229,22 +215,17 @@ void LoadSettings()
/// </summary>
void OpenPanel(object sender, EventArgs e) => pluginPanel.Show();

/// <summary>
/// </summary>
void SaveBuildFiles()
{
string folder = GetBuildFilesStorageFolder();
string fullName = Path.Combine(folder, StorageFileName);
var folder = GetBuildFilesStorageFolder();
var fullName = Path.Combine(folder, StorageFileName);
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
StreamWriter file = new StreamWriter(fullName);
foreach (string line in BuildFilesList)
var file = new StreamWriter(fullName);
foreach (var line in BuildFilesList)
file.WriteLine(line);
file.Close();
}

/// <summary>
/// </summary>
/// <returns></returns>
static string GetBuildFilesStorageFolder() => Path.Combine(Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath), "obj");

#endregion
Expand All @@ -256,15 +237,15 @@ void SaveBuildFiles()
void OnTreeSelectionChanged()
{
if (!(projectTree?.SelectedNode is FileNode)) return;
string path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath);
var path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath);
if (BuildFilesList.Contains(path) || Path.GetExtension(path) != ".xml") return;
projectTree.ContextMenuStrip.Items.Add(new ToolStripSeparator());
projectTree.ContextMenuStrip.Items.Add("Add as Ant Build File", pluginImage, OnAddAsAntBuildFile);
}

void OnAddAsAntBuildFile(object sender, EventArgs e)
{
string path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath);
var path = Path.GetFullPath(((FileNode)projectTree.SelectedNode).BackingPath);
if (BuildFilesList.Contains(path)) return;
BuildFilesList.Add(path);
SaveBuildFiles();
Expand Down
Loading

0 comments on commit fa4a65e

Please sign in to comment.