private void CloneTool() { ListViewItem lvi = GetSelectedItem(); if (lvi == null) { return; } string toolId = lvi.Tag as string; if (toolId == null) { return; } BuildTool oldTool = _buildTools.GetTool(toolId); BuildTool newTool = new BuildTool( Guid.NewGuid().ToString(), oldTool.DocumentType, String.Format(Resources.CloneCopyName, oldTool.DisplayName)); newTool.Action = oldTool.Action; newTool.Path = oldTool.Path; newTool.Args = oldTool.Args; newTool.UserArgs = oldTool.UserArgs; newTool.BuildCommand = oldTool.BuildCommand; newTool.LineParser = oldTool.LineParser; newTool.LineParserName = oldTool.LineParserName; _buildTools.AddTool(newTool); Load(); }
/// <summary> /// Load the registered build tools from the session persistence /// store. /// </summary> public void LoadTools() { _buildTools.ClearAll(); List <String> toolStrings = _persistenceManager.ReadStrings( Constants.KEY_TOOLS_COLLECTION); foreach (string s in toolStrings) { BuildTool tool = BuildTool.Parse(s); if (tool != null) { _buildTools.AddTool(tool); } } List <String> selectedToolStrings = _persistenceManager.ReadStrings( Constants.KEY_SELECTED_TOOLS_COLLECTION); foreach (string s in selectedToolStrings) { _buildTools.SelectTool(s); } }
/// <summary> /// Determine if a selected tool is available for a document /// type/build tool action combination. /// </summary> /// <param name="documentType">The document type.</param> /// <param name="action">The build action.</param> /// <returns>True if a selected tool is available.</returns> public bool SelectedToolIsAvailable(DocumentType documentType, string action) { BuildTool selectedTool = GetSelectedTool(documentType, action); if (selectedTool == null) { return(false); } return(selectedTool.BuildCommand != null); }
/********************************************************************** * SRC_PATH - source file path * SRC_FILE - source file name * SRC_NAME - source file name without extension * SRC_EXT - source file extension * OUT_PATH - output file path * OUT_FILE - output file name * OUT_NAME - output file name without extension * OUT_EXT - output file extension * IDE_HOME - QuickSharp installation directory * USR_HOME - User's data directory * WORKSPACE - workspace folder name * COMMON_OPT - options provided by the build tool * EMBEDDED_OPT - options embedded in the source * RUNTIME_OPT - runtime arguments embedded in the source **********************************************************************/ /// <summary> /// Expand a build tool template string by translating /// macro definitions into their actual values. /// </summary> /// <param name="template">The template.</param> /// <param name="buildTool">The build tool it belongs to.</param> /// <param name="srcText">The source code on which the build tool is being invoked.</param> /// <param name="srcFile">The name of the source file on which the build tool is being invoked.</param> /// <param name="outFile">The name of the output file of the build tool.</param> /// <returns>The expanded template.</returns> public string ExpandGenericMacros( string template, BuildTool buildTool, string srcText, FileInfo srcFile, FileInfo outFile) { string SRC_PATH = srcFile.FullName; string SRC_FILE = srcFile.Name; string SRC_NAME = Path.GetFileNameWithoutExtension(srcFile.Name); string SRC_EXT = srcFile.Extension; string OUT_PATH = outFile.FullName; string OUT_FILE = outFile.Name; string OUT_NAME = Path.GetFileNameWithoutExtension(outFile.Name); string OUT_EXT = outFile.Extension; string IDE_HOME = _applicationManager.QuickSharpHome; string USR_HOME = _applicationManager.QuickSharpUserHome; string USR_DOCS = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string SYSTEM = Environment.SystemDirectory; string PFILES = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); string WORKSPACE = srcFile.Directory.Name; string COMMON_OPT = buildTool.UserArgs; string EMBEDDED_OPT = GetCompilerOptions(srcText); string RUNTIME_OPT = GetRuntimeOptions(srcText); /* * We allow carriage returns/newlines to be stored in the * build command string to improve ease of editing but we * need to take them out here. */ COMMON_OPT = COMMON_OPT.Replace("\r\n", " "); template = template.Replace("${SRC_PATH}", SRC_PATH); template = template.Replace("${SRC_FILE}", SRC_FILE); template = template.Replace("${SRC_NAME}", SRC_NAME); template = template.Replace("${SRC_EXT}", SRC_EXT); template = template.Replace("${OUT_PATH}", OUT_PATH); template = template.Replace("${OUT_FILE}", OUT_FILE); template = template.Replace("${OUT_NAME}", OUT_NAME); template = template.Replace("${OUT_EXT}", OUT_EXT); template = template.Replace("${IDE_HOME}", IDE_HOME); template = template.Replace("${USR_HOME}", USR_HOME); template = template.Replace("${USR_DOCS}", USR_DOCS); template = template.Replace("${SYSTEM}", SYSTEM); template = template.Replace("${PFILES}", PFILES); template = template.Replace("${WORKSPACE}", WORKSPACE); template = template.Replace("${COMMON_OPT}", COMMON_OPT); template = template.Replace("${EMBEDDED_OPT}", EMBEDDED_OPT); template = template.Replace("${RUNTIME_OPT}", RUNTIME_OPT); return(template); }
/// <summary> /// Duplicate an existing build tool. /// </summary> /// <returns>A BuildTool instance.</returns> public BuildTool Clone() { BuildTool tool = new BuildTool(_id, _documentType, _displayName); tool.Action = _toolAction; tool.Path = _toolPath; tool.Args = _toolArgs; tool.UserArgs = _userArgs; tool.LineParserName = _lineParserName; tool.LineParser = _lineParser; tool.BuildCommand = _buildCommand; return(tool); }
/// <summary> /// Finalize the build tools registered by a plugin. This must be called /// whenever additional tools are added to the build tool system and is required /// to populate the tool definitions with additional data not stored in the /// saved definitions (e.g. line parser instances). /// </summary> /// <param name="documentType">The document type of the tools being registered.</param> public void UpdateTools(DocumentType documentType) { Dictionary <String, BuildTool> tools = _buildTools.GetTools(documentType); foreach (string id in tools.Keys) { BuildTool tool = tools[id]; tool.BuildCommand = GetBuildCommand( tool.DocumentType, tool.Action); if (!String.IsNullOrEmpty(tool.LineParserName)) { tool.LineParser = GetLineParser(tool.LineParserName); } } }
private void Load() { _buildTools.SortTools(); _listView.Items.Clear(); foreach (string id in _buildTools.Tools.Keys) { BuildTool tool = _buildTools.Tools[id]; ListViewItem lvi = new ListViewItem(); lvi.Text = tool.DocumentType.ToString(); lvi.SubItems.Add(tool.Action); lvi.SubItems.Add(tool.DisplayName); lvi.Tag = tool.Id; _listView.Items.Add(lvi); } }
/// <summary> /// Select a build tool. Selecting a tool makes it the currently /// selected tool for a document type/build action combination. Any /// previously selected tool is deselected. /// </summary> /// <param name="tool">A BuildTool instance.</param> public void SelectTool(BuildTool tool) { DocumentType documentType = tool.DocumentType; string action = tool.Action; foreach (string id in _selectedTools.Keys) { if (_selectedTools[id].DocumentType.Matches(documentType) && _selectedTools[id].Action == action) { _selectedTools.Remove(id); break; } } _selectedTools[tool.Id] = new DocumentTypeAction() { DocumentType = tool.DocumentType, Action = tool.Action }; }
private int CompareBuildTools(string id1, string id2) { BuildTool t1 = _tools[id1]; BuildTool t2 = _tools[id2]; if (t1.DocumentType.Matches(t2.DocumentType)) { if (t1.Action == t2.Action) { return(t1.DisplayName.CompareTo(t2.DisplayName)); } else { return(t1.Action.CompareTo(t2.Action)); } } else { return(t1.DocumentType.CompareTo(t2.DocumentType)); } }
/// <summary> /// Convert a saved tool configuration into a build tool instance. /// </summary> /// <param name="s">The saved configuration.</param> /// <returns>A BuildTool instance.</returns> public static BuildTool Parse(string s) { string [] items = s.Split(Constants.SERIALIZATION_DELIMITER[0]); if (items.Length != 8) { return(null); } BuildTool tool = new BuildTool( items[0], new DocumentType(items[1]), items[2]); tool.Action = items[3]; tool.Path = items[4]; tool.Args = items[5]; tool.UserArgs = items[6]; tool.LineParserName = items[7]; return(tool); }
private BuildCommand GetBuildCommand( FileInfo srcInfo, string action) { if (srcInfo == null) { return(null); } BuildTool buildTool = _buildToolManager.BuildTools.GetSelectedTool( srcInfo.Extension, action); if (buildTool == null || buildTool.BuildCommand == null) { return(null); } BuildCommand buildCommand = buildTool.BuildCommand(buildTool, srcInfo); return(buildCommand); }
/// <summary> /// Determine if a build tool is selected. /// </summary> /// <param name="tool">A BuildTool instance.</param> /// <returns>True if the tool is selected.</returns> public bool ToolIsSelected(BuildTool tool) { return(_selectedTools.ContainsKey(tool.Id)); }
/// <summary> /// Add a tool to the collection. /// </summary> /// <param name="tool">A BuildTool instance.</param> public void AddTool(BuildTool tool) { _tools[tool.Id] = tool; }
/// <summary> /// Load the build tool to be configured or create a new configuration. /// </summary> private void LoadTool() { if (_toolId == null) { _documentTypeComboBox.Enabled = true; _actionComboBox.Enabled = true; _parserComboBox.Enabled = true; _documentTypeComboBox.SelectedIndex = 0; } else { BuildTool tool = _buildTools.Tools[_toolId]; if (tool == null) { throw new Exception("Error retrieving build tool"); } _documentTypeComboBox.Enabled = false; _actionComboBox.Enabled = false; _parserComboBox.Enabled = true; int i = _documentTypeComboBox.Items.IndexOf( tool.DocumentType.ToString()); if (i != -1) { _documentTypeComboBox.SelectedIndex = i; } UpdateActionComboBox(); i = _actionComboBox.Items.IndexOf(tool.Action); if (i != -1) { _actionComboBox.SelectedIndex = i; } UpdateParserComboBox(); if (String.IsNullOrEmpty(tool.LineParserName)) { _parserComboBox.SelectedIndex = 0; } else { i = _parserComboBox.Items.IndexOf(tool.LineParserName); if (i != -1) { _parserComboBox.SelectedIndex = i; } } _displayNameTextBox.Text = tool.DisplayName; _toolPathTextBox.Text = tool.Path; _toolArgsTextBox.Text = tool.Args; _userArgsTextBox.Text = tool.UserArgs; } }
/// <summary> /// Create or update the tool in the build tools collection. /// </summary> /// <returns></returns> private bool SaveTool() { _displayNameTextBox.BackColor = Color.Empty; _toolPathTextBox.BackColor = Color.Empty; string id = (_toolId != null) ? _toolId : Guid.NewGuid().ToString(); string documentTypeString = _documentTypeComboBox.SelectedItem as string; string displayName = _displayNameTextBox.Text.Trim(); string toolAction = _actionComboBox.SelectedItem as string; string toolPath = _toolPathTextBox.Text.Trim(); string toolArgs = _toolArgsTextBox.Text.Trim(); string userArgs = _userArgsTextBox.Text.Trim(); string lineParserName = String.Empty; if (_parserComboBox.SelectedIndex > 0) { lineParserName = _parserComboBox.SelectedItem as string; } id = MakeSafeForSerialization(id); documentTypeString = MakeSafeForSerialization(documentTypeString); displayName = MakeSafeForSerialization(displayName); toolAction = MakeSafeForSerialization(toolAction); toolPath = MakeSafeForSerialization(toolPath); toolArgs = MakeSafeForSerialization(toolArgs); userArgs = MakeSafeForSerialization(userArgs); lineParserName = MakeSafeForSerialization(lineParserName); bool validated = true; if (displayName == String.Empty) { validated = false; _displayNameTextBox.BackColor = Color.Yellow; } if (toolPath == String.Empty) { validated = false; _toolPathTextBox.BackColor = Color.Yellow; } if (!validated) { return(false); } DocumentType documentType = new DocumentType(documentTypeString); BuildTool tool = new BuildTool(id, documentType, displayName); tool.Action = toolAction; tool.Path = toolPath; tool.Args = toolArgs; tool.UserArgs = userArgs; tool.BuildCommand = _buildToolManager.GetBuildCommand(documentType, toolAction); tool.LineParserName = lineParserName; tool.LineParser = _buildToolManager.GetLineParser(tool.LineParserName); _buildTools.AddTool(tool); return(true); }