From e798cd51f95f2ea0c1982bb55edbed8396f07186 Mon Sep 17 00:00:00 2001 From: Jeremie Laval Date: Fri, 16 Nov 2012 17:20:48 +0000 Subject: [macdoc] Add --search flag to macdoc. The flag will make macdoc opens a untitled window (in addition to the restored ones), switch it to search mode, prefill the search entry and launch the search itself. --- AppDelegate.cs | 10 ++++++++++ MyDocument.cs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/AppDelegate.cs b/AppDelegate.cs index 8bd081b..0f56d9e 100644 --- a/AppDelegate.cs +++ b/AppDelegate.cs @@ -113,6 +113,16 @@ namespace macdoc public override void FinishedLaunching (NSObject notification) { + // Check if we are loaded with a search term and load a document for it + var args = Environment.GetCommandLineArgs (); + NSError error; + var searchArgIdx = Array.IndexOf (args, "--search"); + if (searchArgIdx != -1 && args.Length > searchArgIdx + 1 && !string.IsNullOrEmpty (args [searchArgIdx + 1])) { + var document = controller.OpenUntitledDocument (true, out error); + if (document != null) + ((MyDocument)document).LoadWithSearch (args[searchArgIdx + 1]); + } + var indexManager = IndexUpdateManager; indexManager.CheckIndexIsFresh ().ContinueWith (t => { if (t.IsFaulted) diff --git a/MyDocument.cs b/MyDocument.cs index 48a652c..49a7554 100644 --- a/MyDocument.cs +++ b/MyDocument.cs @@ -46,6 +46,16 @@ namespace macdoc return "Mono Documentation Browser"; } } + + public void LoadWithSearch (string searchTerm) + { + if (!string.IsNullOrEmpty (searchTerm)) { + toolbarSearchEntry.StringValue = searchTerm; + tabSelector.SelectAt (2); + Search (searchTerm); + Console.WriteLine ("Searched: '{0}'", searchTerm); + } + } public override bool ReadFromUrl (NSUrl url, string typeName, out NSError outError) { -- cgit v1.2.3