-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeeSAPLogonExt.cs
More file actions
152 lines (113 loc) · 4.86 KB
/
KeeSAPLogonExt.cs
File metadata and controls
152 lines (113 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright (C) 2016 Marko Graf
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using KeePass.Plugins;
namespace KeeSAPLogon
{
public sealed class KeeSAPLogonExt : Plugin, IDisposable
{
public const string PlugInName = "KeeSAPLogon";
private static IPluginHost m_host = null;
private ToolStripMenuItem m_tsmiSetDlg = null;
private LogonColumnProvider m_prov = null;
private SAPLogonOpt m_provOpt = null;
private bool m_disposed = false;
//---------------------------------------------------------------------------------------------------
// Class Destructor
//---------------------------------------------------------------------------------------------------
// Use C# destructor syntax for finalization code.
~KeeSAPLogonExt()
{
// Simply call Dispose(false).
Dispose(false);
}
//---------------------------------------------------------------------------------------------------
// Interface Implementation: KeePass.Plugins.Plugin
//---------------------------------------------------------------------------------------------------
#region KeePass.Plugins.Plugin implementation
public override Image SmallIcon { get { return KeeSAPLogon.Properties.Resources.KeeSAPLogonIcon_png; } }
public override string UpdateUrl { get { return KeeSAPLogon.Properties.Resources.URLVersionCheck; } }
public override bool Initialize(IPluginHost host)
{
Debug.Assert(host != null, PlugInName + ": " + "No host instance available.", "PlugIn host instance is null.");
Terminate();
m_host = host;
if (host != null)
{
m_provOpt = new SAPLogonOpt(host.CustomConfig);
m_prov = new LogonColumnProvider(host, m_provOpt);
m_host.ColumnProviderPool.Add(m_prov);
// Get a reference to the 'Tools' menu item container
ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
// Add the popup menu item
m_tsmiSetDlg = new ToolStripMenuItem();
m_tsmiSetDlg.Text = Translatable.ButtonSAPLogonDlg;
m_tsmiSetDlg.ToolTipText = Translatable.ButtonSAPLogonDlg;
m_tsmiSetDlg.Image = KeeSAPLogon.Properties.Resources.KeeSAPLogonIcon_png;
m_tsmiSetDlg.Click += this.OnSettingsDlg;
tsMenu.Add(m_tsmiSetDlg);
return true;
}
return false;
}
public override void Terminate()
{
if (m_host != null)
{
if (m_prov != null)
{
m_host.ColumnProviderPool.Remove(m_prov);
}
// Remove all of our menu items
ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
if (m_tsmiSetDlg != null)
{
m_tsmiSetDlg.Click -= this.OnSettingsDlg;
tsMenu.Remove(m_tsmiSetDlg);
}
m_host = null;
}
base.Terminate();
}
#endregion
//---------------------------------------------------------------------------------------------------
// Interface Implementation: IDisposable
//---------------------------------------------------------------------------------------------------
#region IDisposable implementation
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
//---------------------------------------------------------------------------------------------------
// Private Methods
//---------------------------------------------------------------------------------------------------
private void Dispose(bool disposing)
{
if (!m_disposed)
{
if (disposing)
{
// Free other state (managed objects).
m_tsmiSetDlg.Dispose();
m_prov.Dispose();
m_provOpt.Dispose();
}
// Free your own state (unmanaged objects).
// Set large fields to null.
m_disposed = true;
}
}
private void OnSettingsDlg(object sender, EventArgs e)
{
OptionDlg dlg = new OptionDlg(m_host.MainWindow, new SAPLogonOpt(m_host.CustomConfig));
dlg.ShowDialog();
dlg.Dispose();
}
}
}