Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
berrnd committed Jun 7, 2013
1 parent 4238939 commit e7eb2c1
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 1 deletion.
20 changes: 20 additions & 0 deletions AutoTypeCustomFieldPicker.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoTypeCustomFieldPicker", "AutoTypeCustomFieldPicker\AutoTypeCustomFieldPicker.csproj", "{E6AC839D-012F-4339-B6E9-71EDF208720E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6AC839D-012F-4339-B6E9-71EDF208720E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6AC839D-012F-4339-B6E9-71EDF208720E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6AC839D-012F-4339-B6E9-71EDF208720E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6AC839D-012F-4339-B6E9-71EDF208720E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
81 changes: 81 additions & 0 deletions AutoTypeCustomFieldPicker/AutoTypeCustomFieldPicker.csproj
@@ -0,0 +1,81 @@
<?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>{E6AC839D-012F-4339-B6E9-71EDF208720E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AutoTypeCustomFieldPicker</RootNamespace>
<AssemblyName>AutoTypeCustomFieldPicker</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="KeePass, Version=2.22.0.21283, Culture=neutral, PublicKeyToken=fed2ed7716aecf5c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<ExecutableExtension>.exe</ExecutableExtension>
<HintPath>Resources\KeePass.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AutoTypeCustomFieldPickerExt.cs" />
<Compile Include="DlgPickCustomField.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="DlgPickCustomField.Designer.cs">
<DependentUpon>DlgPickCustomField.cs</DependentUpon>
</Compile>
<Compile Include="MyFieldObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\KeePass.exe" />
</ItemGroup>
<ItemGroup>
<Content Include="UpdateInfo.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DlgPickCustomField.resx">
<DependentUpon>DlgPickCustomField.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- 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>
53 changes: 53 additions & 0 deletions AutoTypeCustomFieldPicker/AutoTypeCustomFieldPickerExt.cs
@@ -0,0 +1,53 @@
using System.Windows.Forms;
using KeePass.Plugins;
using KeePass.Util;

namespace AutoTypeCustomFieldPicker
{
public sealed class AutoTypeCustomFieldPickerExt : Plugin
{
private const string PLACEHOLDER = "{PICKCUSTOMFIELD}";

private IPluginHost PluginHost = null;
private string CurrentPlaceholderResolved = string.Empty;

public override bool Initialize(IPluginHost host)
{
this.PluginHost = host;
if (this.PluginHost == null)
return false;

AutoType.FilterSendPre += this.AutoType_FilterSendPre;
AutoType.SequenceQuery += this.AutoType_SequenceQuery;

return true;
}

public override void Terminate()
{
AutoType.FilterSendPre -= this.AutoType_FilterSendPre;
AutoType.SequenceQuery -= this.AutoType_SequenceQuery;
}

private void AutoType_FilterSendPre(object sender, AutoTypeEventArgs e)
{
if (!string.IsNullOrEmpty(this.CurrentPlaceholderResolved) && e.Entry.GetAutoTypeSequence().Contains(this.CurrentPlaceholderResolved))
e.Entry.AutoType.DefaultSequence = e.Entry.AutoType.DefaultSequence.Replace(this.CurrentPlaceholderResolved, PLACEHOLDER);
}

private void AutoType_SequenceQuery(object sender, SequenceQueryEventArgs e)
{
if (e.Entry.GetAutoTypeSequence().Contains(PLACEHOLDER))
{
DlgPickCustomField picker = new DlgPickCustomField();
picker.PickCustomField(PLACEHOLDER, e.Entry);

if (picker.DialogResult == DialogResult.OK && picker.SelectedField != null)
{
this.CurrentPlaceholderResolved = picker.SelectedField.Value;
e.Entry.AutoType.DefaultSequence = e.Entry.AutoType.DefaultSequence.Replace(PLACEHOLDER, picker.SelectedField.Value);
}
}
}
}
}
106 changes: 106 additions & 0 deletions AutoTypeCustomFieldPicker/DlgPickCustomField.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions AutoTypeCustomFieldPicker/DlgPickCustomField.cs
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Windows.Forms;
using KeePassLib;
using KeePassLib.Security;

namespace AutoTypeCustomFieldPicker
{
public partial class DlgPickCustomField : Form
{
public DlgPickCustomField()
{
InitializeComponent();
}

public MyFieldObject SelectedField;

public void PickCustomField(string placeholder, PwEntry entry)
{
this.label_PlaceholderInfo.Text = string.Format(this.label_PlaceholderInfo.Text, placeholder);

foreach (KeyValuePair<string, ProtectedString> item in entry.Strings)
this.listBox_CustomFields.Items.Add(new MyFieldObject(item.Key, item.Value.ReadString()));

this.ShowDialog();
}

private void button_OK_Click(object sender, System.EventArgs e)
{
if (this.listBox_CustomFields.SelectedItem != null)
this.SelectedField = this.listBox_CustomFields.SelectedItem as MyFieldObject;

this.Close();
}

private void listBox_CustomFields_DoubleClick(object sender, System.EventArgs e)
{
if (this.listBox_CustomFields.SelectedItem != null)
this.SelectedField = this.listBox_CustomFields.SelectedItem as MyFieldObject;

this.DialogResult = DialogResult.OK;
this.Close();
}

private void button_Cancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}

0 comments on commit e7eb2c1

Please sign in to comment.