private void commandContextToToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (filesView.FocusedItem != null)
     {
         CommandElement pe = (sender as ToolStripMenuItem).Tag as CommandElement;
         if (pe != null)
         {
             ExecuteCommand(filesView.FocusedItem, pe);
             filesView.FocusedItem.EnsureVisible();
         }
     }
 }
        private void commandToToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommandElement pe = (sender as ToolStripMenuItem).Tag as CommandElement;

            if (pe != null)
            {
                InProgress = true;
                foreach (ListViewItem item in filesView.CheckedItems)
                {
                    ExecuteCommand(item, pe);
                    if (CheckCancel())
                    {
                        break;
                    }
                }
                InProgress = false;
            }
        }
        private void ExecuteCommand(ListViewItem item, CommandElement command)
        {
            string commandString = String.Empty;

            try
            {
                FB2File fc = item.Tag as FB2File;
                if (!String.IsNullOrEmpty(command.OnlyWithExtension))
                {
                    if (!fc.FileInformation.FullName.ToLowerInvariant().EndsWith(command.OnlyWithExtension.ToLowerInvariant()))
                    {
                        AddMessageRN(String.Format(Properties.Resources.ExecuteCommandWrongExtension, fc.FileInformation.FullName, command.OnlyWithExtension));
                        return;
                    }
                }
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow  = command.CreateNoWindow;
                startInfo.FileName        = command.FileName;
                startInfo.UseShellExecute = false;
                commandString             = String.Format(command.Arguments, fc.FileInformation.FullName);
                startInfo.Arguments       = commandString;

                AddMessageRN(String.Format(Properties.Resources.ExecuteCommand, command.FileName, commandString));
                using (Process exeProcess = Process.Start(startInfo))
                {
                    if (command.WaitAndReload)
                    {
                        exeProcess.WaitForExit();
                        fc.Reload();
                        UpdateItem(item);
                    }
                }
            }
            catch (Exception ex)
            {
                AddMessageRN(String.Format(Properties.Resources.ExecuteCommandError, command.FileName, ex.Message));
            }
        }