4

Is there a way by which, when I open a query in LINQPad, it executes it and puts me in the result-only view? The intended use case for this is to write small applications within LINQPad. I don't want to hit F5 and Ctrl+Shift+R every time.

The motivation for this is the recently released RegEx utility in 5.36. This is also a script that does the same.

Shrayas
  • 6,784
  • 11
  • 37
  • 54
  • I can partially help you - put `System.Windows.Forms.SendKeys.SendWait("^+R");` after the opening brace for `Main` to autotype Ctrl-Shift-R. – NetMage Apr 01 '19 at 20:14

2 Answers2

7

I've added an Util.OpenQuery method to the next build:

public static Task<bool> OpenQuery (string queryPath, bool run = false,
                                    bool hideEditor = false, params object[] args)

You'll then be able to call this from the Automator query:

void Main (System.Windows.Forms.Keys key, string currentQueryPath)
{
    if (key == (Keys.Shift | Keys.Control | Keys.Alt | Keys.F1))
        Util.OpenQuery (@"my query.linq", true, true);
}

This will allow you to automate up to 12 queries (with hotkeys Alt+Shift+Ctrl+ [F1-F12])

Joe Albahari
  • 30,118
  • 7
  • 80
  • 91
  • 1
    This is exactly what I want! I look forward to the next build, Joe. Thanks so much for this tool and your consistent work to make it great. – Shrayas Apr 02 '19 at 05:34
  • 1
    Small feature request: I would tend to forget which queries I've bound to which hotkeys eventually. Would it be possible for you to implement something similar to your optimize directive for this? I could start the query with `#LINQPad RunOnOpen` or something like that which, when I open the query would run it and another `#LINQPad HideEditor` would hide the editor? Just throwing some thoughts your way :) Thanks again. – Shrayas Apr 02 '19 at 05:36
  • I will also be added an "Open and Run" shortcuts to the navigate query dialog (Control+comma): https://twitter.com/linqpad/status/1113001784794992641 Will this help? Note that a #LINQPad RunOnOpen option on a query could be considered a security risk. – Joe Albahari Apr 03 '19 at 06:22
  • Yes, that would help for sure. Except for the fact that I have to remember to open it in that way. But I do get your point on it being a security risk. – Shrayas Apr 04 '19 at 09:33
  • A new LINQPad beta has now been released: https://www.linqpad.net/download.aspx#beta – Joe Albahari Apr 05 '19 at 03:20
  • YOU ARE AMAZING – Shrayas Apr 10 '19 at 11:16
3

You can launch LINQPad from the command line with arguments to run a script file:

linqpad "path to file" -run

Then if you add the line

System.Windows.Forms.SendKeys.SendWait("^+R");

As the first line in Main, the code will be hidden.

Note the linked answer's suggestion for closing LINQPad at the end of the script.

NetMage
  • 26,163
  • 3
  • 34
  • 55
  • Thanks for this, @NetMage. But I don't want to open a query from the commandline. I meant that I would be _inside_ linqpad and I open the query. Much like the RegEx evaluator that Joe put in the latest build :) I appreciate the answer however, I learnt about the `SendKeys` method from this. – Shrayas Apr 02 '19 at 05:32