Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            CmdOptions options = new CmdOptions();

            Parser.Default.ParseArguments <CmdOptions>(args).WithParsed(o =>
            {
                options = o;
            });

            bool mutexCreated = true;

            using (Mutex mutex = new Mutex(true, "GrepWindowsMutex", out mutexCreated))
            {
                if (mutexCreated || !options.OneInstance)
                {
                    if (mutexCreated)
                    {
                        NamedPipes.CreatePipe();
                    }
                    Application.Run(new Form1(options.Directory.Trim(new char[] { '\"' }), options.Pattern));
                }
                else
                {
                    if (options.Pattern != String.Empty)
                    {
                        NamedPipes.SendSearchPattern(options.Directory.Trim(new char[] { '\"' }), options.Pattern);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles when someone double clicks in the results text box.  Sends a message to an external application.
        /// </summary>
        private void TextBox_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            int rowIndex = TextBox.GetLineFromCharIndex(TextBox.SelectionStart);

            if (rowIndex >= 0 && rowIndex < TextBox.Lines.Length && TextBox.Lines[rowIndex].Length > 0)
            {
                if (Char.IsDigit(TextBox.Lines[rowIndex][0]))
                {
                    int lineNumber = Int32.Parse(TextBox.Lines[rowIndex].Substring(0, TextBox.Lines[rowIndex].IndexOf(":")));
                    for (int i = rowIndex - 1; i >= 0; i--)
                    {
                        if (!Char.IsDigit(TextBox.Lines[i][0]))
                        {
                            try
                            {
                                if (Settings.get().ExternalAppType == Settings.BuiltInExternalApps.VISUAL_STUDIO)
                                {
                                    NamedPipes.SendFileAndLine(lineNumber.ToString() + "?" + TextBox.Lines[i]);
                                }
                                else
                                {
                                    Process.Start(Settings.get().ExternalApplication, replaceVariables(Settings.get().WithLineNumberArgs, lineNumber, TextBox.Lines[i]));
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.get().AddError(ex.Message);
                                MessageBox.Show(ex.Message);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    String filepath = TextBox.Lines[rowIndex];
                    if (!File.Exists(filepath))
                    {
                        filepath = Path.Combine(SearchedDirectory, filepath);
                    }
                    if (File.Exists(filepath))
                    {
                        try
                        {
                            if (Settings.get().ExternalAppType == Settings.BuiltInExternalApps.VISUAL_STUDIO)
                            {
                                NamedPipes.SendFileAndLine("?" + filepath);
                            }
                            else
                            {
                                Process.Start(Settings.get().ExternalApplication, replaceVariables(Settings.get().FileArgs, -1, filepath));
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.get().AddError(ex.Message);
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }