//------------------------------------------------------------------------- public void SwapEntries(TemplateEntry e1, TemplateEntry e2) { int index1 = m_entries.IndexOf(e1); int index2 = m_entries.IndexOf(e2); if (index1 >= 0 && index2 >= 0 && index1 != index2) { if (index1 < index2) { m_entries.Remove(e2); m_entries.Insert(index1, e2); m_entries.Remove(e1); m_entries.Insert(index2, e1); } else { m_entries.Remove(e1); m_entries.Insert(index2, e1); m_entries.Remove(e2); m_entries.Insert(index1, e2); } } }
//------------------------------------------------------------------------- public void AddEntry(TemplateEntry newEntry) { // check name isn't already used foreach (TemplateEntry entry in m_entries) { if (entry.Description.ToLower() == newEntry.Description.ToLower()) { throw new Exception("Entry '" + newEntry.Description + "' already exists."); } } // add it m_entries.Add(newEntry); }
//------------------------------------------------------------------------- public void LoadFromFile(string fullFilename) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fullFilename); // template info XmlNodeList nodes = xmlDoc.GetElementsByTagName("Info"); XmlElement infoElement = nodes[0] as XmlElement; m_name = infoElement.Attributes["name"].Value; if (infoElement.HasAttribute("isArchived")) { m_isArchived = Boolean.Parse(infoElement.Attributes["isArchived"].Value); } // entries XmlNodeList entryElements = xmlDoc.GetElementsByTagName("Entry"); foreach (XmlNode xmlNode in entryElements) { TemplateEntry newEntry = null; // get the type XmlElement entryElement = (xmlNode as XmlElement); string type = entryElement.Attributes["type"].Value; // create the specified type of entry switch (type) { case TemplateShortcutEntry.c_typeName: newEntry = new TemplateShortcutEntry(entryElement); break; case TemplateCommonValueCollectionEntry.c_typeName: newEntry = new TemplateCommonValueCollectionEntry(entryElement); break; } // add it to the list if (newEntry != null) { AddEntry(newEntry); } } }
//------------------------------------------------------------------------- private void moveShortcutDownBtn_Click(object sender, EventArgs e) { try { if (shortcutTree.SelectedNode == null) { return; } Project prj = (projectList.SelectedItem as Project); TemplateEntry entry1 = (shortcutTree.SelectedNode.Tag as TemplateEntry); if (prj == null || entry1 == null) { return; } if (shortcutTree.SelectedNode.NextNode == null) { return; } TemplateEntry entry2 = (shortcutTree.SelectedNode.NextNode.Tag as TemplateEntry); if (entry2 == null) { return; } prj.Template.SwapEntries(entry1, entry2); RefreshShortcutTree(); prj.WriteToFile(); } catch (Exception ex) { ErrorMsg(ex.Message); } }
//------------------------------------------------------------------------- private void shortcutTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { try { Project prj = (projectList.SelectedItem as Project); if (prj != null) { TemplateEntry entry = (shortcutTree.SelectedNode.Tag as TemplateEntry); if (entry != null) { entry.PerformAction(prj, DateTime.Now.GetHashCode()); } } } catch (Exception ex) { ErrorMsg("An error occured while running this shortcut:" + Environment.NewLine + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace); } }
//------------------------------------------------------------------------- public override bool PerformAction(Project project, int actionHashCode) { //-- Base. if (base.PerformAction(project, actionHashCode) == false) { return(true); } //-- Confirm? if (m_confirmBeforeRunning) { if (MessageBox.Show(m_project.GetCommonValue("Run shortcut '" + Description + "'?", false), "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel) { return(false); } } //-- Run the process. if (m_filename != "") { string resolvedFilename = project.GetCommonValue(m_filename, false); resolvedFilename = resolvedFilename.Replace("\"", ""); bool isExecutable = (resolvedFilename.Contains(".exe") || resolvedFilename.Contains(".bat")); ProcessStartInfo info = new ProcessStartInfo(); info.FileName = resolvedFilename; info.Arguments = GetArgumentString(m_args, m_argStates, project); info.UseShellExecute = !isExecutable; info.WorkingDirectory = Path.GetDirectoryName(info.FileName); if (isExecutable) { info.EnvironmentVariables.Add("ALICE_RESOURCE_PATH", Program.g_path + "\\res\\"); } foreach (string key in m_environmentVars.Keys) { if (EnvironmentVarStates[key] == false) { continue; } string value; if (m_environmentVars.TryGetValue(key, out value)) { value = project.GetCommonValue(value, true); if (info.EnvironmentVariables.ContainsKey(key)) { info.EnvironmentVariables[key] = value; } else { info.EnvironmentVariables.Add(key, value); } } } Process.Start(info); } //-- Run any linked shortcuts. foreach (string description in m_linkedShortcutDescriptions) { TemplateEntry entry = project.Template.GetEntryWithDescription(description); if (entry != null) { entry.PerformAction(project, actionHashCode); } } return(true); }
//------------------------------------------------------------------------- public void DeleteEntry(TemplateEntry entry) { m_entries.Remove(entry); }