Skip to content

Commit

Permalink
issue 43: mostly done, but still working on getting to work with an I…
Browse files Browse the repository at this point in the history
…Enumerable (not directly supported by the data grid)
  • Loading branch information
stephen.swensen committed Nov 2, 2013
1 parent 055955d commit aac3e58
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Debug.FsEye/Debug.FsEye.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<Reference Include="System.Windows.Forms.DataVisualization" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FsEye.DataGridView.Plugin\FsEye.DataGridView.Plugin.fsproj">
<Name>FsEye.DataGridView.Plugin</Name>
<Project>{cc563dcc-2eaf-4822-b4ce-9d80acca6b5e}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\FsEye.PropertyGrid.Plugin\FsEye.PropertyGrid.Plugin.fsproj">
<Name>FsEye.PropertyGrid.Plugin</Name>
<Project>{1f9b8cb8-8c0c-424c-9035-6562b637a233}</Project>
Expand Down
4 changes: 4 additions & 0 deletions Debug.FsEye/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ open System
open System.Drawing
open System.Windows.Forms

type Student = { mutable Name:string; Age:int }

module Main =
let initEye() =
let eye = new Swensen.FsEye.Forms.EyeForm()
Expand All @@ -12,6 +14,8 @@ module Main =
eye.Watch("some null value", null, typeof<System.Collections.Generic.Dictionary<int,string>>)
let value = ([|3.2; 2.; 1.; -3.; 23.|],[|"a";"b";"c";"d";"e"|])
eye.Watch("series", value, value.GetType())
let value = [{Name="Tom"; Age=3};{Name="Jane"; Age=9}] |> Seq.toArray
eye.Watch("series2", value, value.GetType())
eye.Watch("eye", eye, eye.GetType())
eye

Expand Down
39 changes: 39 additions & 0 deletions FsEye.DataGridView.Plugin/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace FsEye.DataGridView.Plugin

open System.Reflection
open System.Runtime.CompilerServices
open System.Runtime.InteropServices

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[<assembly: AssemblyTitle("FsEye.DataGridView.Plugin")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("FsEye.DataGridView.Plugin")>]
[<assembly: AssemblyCopyright("Copyright © Stephen Swensen 2013")>]
[<assembly: AssemblyTrademark("")>]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[<assembly: ComVisible(false)>]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[<assembly: Guid("02476582-997c-4780-859a-e81188e8339b")>]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[<assembly: AssemblyVersion("1.0.0.*")>]
[<assembly: AssemblyFileVersion("1.0.0.*")>]

()
62 changes: 62 additions & 0 deletions FsEye.DataGridView.Plugin/DataGridViewPlugin.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Swensen.FsEye.Plugins

open System
open Swensen.FsEye
open System.Windows.Forms
open System.Drawing

//todo:share common code between this plugin and the PropertyGrid plugin

module private Helpers =
//see http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx
let ValidDataSourceTypes = [
typeof<System.Collections.IList>
typeof<System.ComponentModel.IListSource>
typeof<System.ComponentModel.IBindingList>
typeof<System.ComponentModel.IBindingListView>]

///A DataGridView-based watch viewer
type DataGridViewWatchViewer() =
let panel = new Panel()

let dgv = new DataGridView(Dock=DockStyle.Fill)
do
panel.Controls.Add(dgv)

let labelPanel = new FlowLayoutPanel(Dock=DockStyle.Top, AutoSize=true, Padding=Padding(0,3,3,5))
let labelLabel = new Label(Text="Source Expression:", AutoSize=true)
let expressionLabel = new Label(AutoSize=true)
do
labelLabel.Font <- new Font(labelLabel.Font, FontStyle.Bold)
labelPanel.Controls.Add(labelLabel)

labelPanel.Controls.Add(expressionLabel)

panel.Controls.Add(labelPanel)

interface IWatchViewer with
///Set or refresh the DataGridView DataSource with the given value.
member this.Watch(label, value, ty) =
expressionLabel.Text <- label
// let value =
// if not (Helpers.ValidDataSourceTypes |> List.exists (fun validTy -> validTy.IsAssignableFrom(ty))) then //must be non-generic IEnumerable
// value :?> System.Collections.IEnumerable |> Seq.cast<obj> |> Seq.toArray :> obj //arrays implement IList
// else
// value
dgv.DataSource <- value
///Get the underlying Control of this watch view
member this.Control = panel :> Control

///A Plugin that creates DataGridViewWatchViewers
type DataGridViewPlugin() =
interface IPlugin with
///"Property Grid"
member __.Name = "Data Grid"
///Create a new instance of a DataGridViewWatchViewer
member __.CreateWatchViewer() = new DataGridViewWatchViewer() :> IWatchViewer
///Returns true if and only if the given value is not null and the given type implements one of the interfaces supported by DataGridView.DataSource.
member this.IsWatchable(value:obj, ty:Type) =
//we convert non-generic IEnumerables to ILists for convenience
//let validTys = typeof<System.Collections.IEnumerable> :: Helpers.ValidDataSourceTypes
let validTys = Helpers.ValidDataSourceTypes
value <> null && (validTys |> List.exists (fun validTy -> validTy.IsAssignableFrom(ty)))
63 changes: 63 additions & 0 deletions FsEye.DataGridView.Plugin/FsEye.DataGridView.Plugin.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{cc563dcc-2eaf-4822-b4ce-9d80acca6b5e}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>FsEye.DataGridView.Plugin</RootNamespace>
<AssemblyName>FsEye.DataGridView.Plugin</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Name>FsEye.DataGridView.Plugin</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\FsEye.DataGridView.Plugin.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\FsEye.DataGridView.Plugin.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="DataGridViewPlugin.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FsEye\FsEye.fsproj">
<Name>FsEye</Name>
<Project>{20de2466-d7b1-4f72-b8f8-51f10f5f186e}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
12 changes: 12 additions & 0 deletions FsEye.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsEye.TreeView.Plugin", "Fs
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsEye.PropertyGrid.Plugin", "FsEye.PropertyGrid.Plugin\FsEye.PropertyGrid.Plugin.fsproj", "{1F9B8CB8-8C0C-424C-9035-6562B637A233}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsEye.DataGridView.Plugin", "FsEye.DataGridView.Plugin\FsEye.DataGridView.Plugin.fsproj", "{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -102,6 +104,16 @@ Global
{1F9B8CB8-8C0C-424C-9035-6562B637A233}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1F9B8CB8-8C0C-424C-9035-6562B637A233}.Release|x86.ActiveCfg = Release|x86
{1F9B8CB8-8C0C-424C-9035-6562B637A233}.Release|x86.Build.0 = Release|x86
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Debug|x86.ActiveCfg = Debug|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Release|Any CPU.Build.0 = Release|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CC563DCC-2EAF-4822-B4CE-9D80ACCA6B5E}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit aac3e58

Please sign in to comment.