Skip to content

Commit 0a77f75

Browse files
committed
Initial jk support for search results pad. Re #193
1 parent e0c723c commit 0a77f75

File tree

5 files changed

+85
-16
lines changed

5 files changed

+85
-16
lines changed

XSVim/Addin.fs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ open System
33
open System.Collections.Generic
44
open MonoDevelop.Components.Commands
55
open MonoDevelop.Core
6-
open MonoDevelop.Core.Text
76
open MonoDevelop.Ide
87
open MonoDevelop.Ide.Editor
98
open MonoDevelop.Ide.Editor.Extension
9+
open MonoDevelop.Ide.FindInFiles
1010

1111
type XSVim() =
1212
inherit TextEditorExtension()
1313
let mutable disposables : IDisposable list = []
1414
let mutable processingKey = false
1515
let mutable config = { insertModeEscapeKey = None }
16-
16+
let searchPads = HashSet<string>()
1717
let initConfig() =
1818
let mapping = SettingsPanel.InsertModeEscapeMapping()
1919
if mapping.Length = 2 then
@@ -26,6 +26,24 @@ type XSVim() =
2626
else
2727
config <- { insertModeEscapeKey = None }
2828

29+
let initializeSearchResultsPads() =
30+
IdeApp.Workbench
31+
|> Option.ofObj
32+
|> Option.iter(fun workbench ->
33+
workbench.Pads
34+
|> Seq.iter(fun pad ->
35+
try
36+
// fetching pad.Content can throw when there is an exception
37+
// when initializing the pad
38+
tryUnbox<SearchResultPad> pad.Content
39+
|> Option.iter(fun pad ->
40+
let padId = pad.Window.Id
41+
if not (searchPads.Contains padId) then
42+
searchPads.Add padId |> ignore
43+
searchResultsPad.initialize pad)
44+
with
45+
| _ -> ()))
46+
2947
member x.FileName = x.Editor.FileName.FullPath.ToString()
3048

3149
member x.State
@@ -34,6 +52,7 @@ type XSVim() =
3452

3553
override x.Initialize() =
3654
treeViewPads.initialize()
55+
x.Editor.FocusLost.Add(fun _ -> initializeSearchResultsPads())
3756

3857
initConfig()
3958
if not (Vim.editorStates.ContainsKey x.FileName) then

XSVim/Properties/AssemblyInfo.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open System.Runtime.CompilerServices
55
[<AutoOpen>]
66
module AddinVersion =
77
[<Literal>]
8-
let version = "0.53.1"
8+
let version = "0.54.1.1"
99

1010
[<assembly: AssemblyTitle("XSVim")>]
1111
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}

XSVim/Reflection.fs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ module Reflection =
3737

3838
// Static member call (on value of type System.Type)?
3939
if (typeof<System.Type>).IsAssignableFrom(o.GetType()) then
40-
let methods = (unbox<Type> o).GetMethods(staticFlags) |> Array.map asMethodBase
41-
let ctors = (unbox<Type> o).GetConstructors(ctorFlags) |> Array.map asMethodBase
42-
Array.concat [ methods; ctors ], null, args
40+
let methods = (unbox<Type> o).GetMethods(staticFlags) |> Array.map asMethodBase
41+
let ctors = (unbox<Type> o).GetConstructors(ctorFlags) |> Array.map asMethodBase
42+
Array.concat [ methods; ctors ], null, args
4343
else
4444
o.GetType().GetMethods(instanceFlags) |> Array.map asMethodBase, o, args
4545

@@ -60,8 +60,8 @@ module Reflection =
6060
// The result type is not an F# function, so we're getting a property
6161
// When the 'o' object is 'System.Type', we access static properties
6262
let typ, flags, instance =
63-
if (typeof<System.Type>).IsAssignableFrom(o.GetType())
64-
then unbox o, staticFlags, null
63+
if (typeof<System.Type>).IsAssignableFrom(o.GetType())
64+
then unbox o, staticFlags, null
6565
else o.GetType(), instanceFlags, o
6666

6767
// Find a property that we can call and get the value
@@ -71,17 +71,24 @@ module Reflection =
7171
let nested = typ.Assembly.GetType(typ.FullName + "+" + name)
7272
// Return nested type if we found one
7373
if nested = null then
74-
failwithf "Property or nested type '%s' not found in '%s'." name typ.Name
74+
failwithf "Property nested type '%s' not found in '%s'." name typ.Name
7575
elif not ((typeof<'R>).IsAssignableFrom(typeof<System.Type>)) then
76-
let rname = (typeof<'R>.Name)
77-
failwithf "Cannot return nested type '%s' as a type '%s'." nested.Name rname
76+
let rname = (typeof<'R>.Name)
77+
failwithf "Cannot return nested type '%s' as a type '%s'." nested.Name rname
7878
else nested |> box |> unbox<'R>
7979
else
80-
// Call property and return result if we found some
81-
let meth = prop.GetGetMethod(true)
82-
if prop = null then failwithf "Property '%s' found, but doesn't have 'get' method." name
83-
try meth.Invoke(instance, [| |]) |> unbox<'R>
84-
with _ -> failwithf "Failed to get value of '%s' property (of type '%s')" name typ.Name
80+
if prop = null then
81+
// if we didn't find a nested type then search for a field
82+
let field = typ.GetField(name, flags)
83+
if not (isNull field) then
84+
field.GetValue(o) |> unbox<'R>
85+
else
86+
failwithf "Property '%s' found, but doesn't have 'get' method." name
87+
else
88+
// Call property and return result if we found some
89+
let meth = prop.GetGetMethod(true)
90+
try meth.Invoke(instance, [| |]) |> unbox<'R>
91+
with _ -> failwithf "Failed to get value of '%s' property (of type '%s')" name typ.Name
8592

8693
let (?<-) (this:obj) (property:string) (value:'Value) =
8794
this.GetType().GetProperty(property).SetValue(this, value, null)

XSVim/SearchResultsPad.fs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace XSVim
2+
open System
3+
open Gtk
4+
open MonoDevelop.Ide.FindInFiles
5+
open MonoDevelop.Ide.Gui.Components
6+
open Reflection
7+
8+
module searchResultsPad =
9+
let select (tree:TreeView) path =
10+
let column = tree.Columns.[0]
11+
tree.Selection.SelectPath path
12+
tree.SetCursor(path, column, false)
13+
14+
let getSelectedPath (tree:TreeView) =
15+
tree.Selection.GetSelectedRows().[0]
16+
17+
let moveDown tree =
18+
let path = getSelectedPath tree
19+
path.Next()
20+
select tree path
21+
22+
let moveUp tree =
23+
let path = getSelectedPath tree
24+
path.Prev() |> ignore
25+
select tree path
26+
27+
let initialize (pad:SearchResultPad) =
28+
let tree:PadTreeView = pad.Control?nativeWidget?treeviewSearchResults
29+
let processKey (key:KeyPressEventArgs) =
30+
match key.Event.Key with
31+
| Gdk.Key.Escape ->
32+
dispatchCommand "MonoDevelop.Ide.Commands.ViewCommands.FocusCurrentDocument"
33+
key.RetVal <- false
34+
| Gdk.Key.j ->
35+
moveDown tree
36+
key.RetVal <- true
37+
| Gdk.Key.k ->
38+
moveUp tree
39+
key.RetVal <- true
40+
| _ -> ()
41+
42+
tree.KeyPressEvent.Add processKey

XSVim/XSVim.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="Types.fs" />
8282
<Compile Include="WindowManagement.fs" />
8383
<Compile Include="ExMode.fs" />
84+
<Compile Include="SearchResultsPad.fs" />
8485
<Compile Include="TreeViewPads.fs" />
8586
<Compile Include="XSVim.fs" />
8687
<Compile Include="Addin.fs" />

0 commit comments

Comments
 (0)