Menu

[6edf59]: / PluginGrid.cs  Maximize  Restore  History

Download this file

381 lines (346 with data), 16.5 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
//-----------------------------------------------------------------------
// <copyright file="PluginGrid.cs" company="NoteFly">
// NoteFly a note application.
// Copyright (C) 2011-2012 Tom
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
//-----------------------------------------------------------------------
namespace NoteFly
{
using System;
using System.IO;
using System.Windows.Forms;
/// <summary>
/// PluginGrid gui object class
/// </summary>
public sealed partial class PluginGrid : UserControl
{
/// <summary>
/// The minimum width of the control.
/// </summary>
private const int MINWITH = 50;
/// <summary>
/// Array with all enable/disable buttons for every plugin.
/// </summary>
private Button[] btnPluginsStatus;
/// <summary>
/// All the tablelayouts panel for every plugin.
/// </summary>
private TableLayoutPanel[] tlpnlPlugins;
/// <summary>
/// The tooltip.
/// </summary>
private ToolTip tooltip;
/// <summary>
/// Initializes a new instance of the PluginGrid class.
/// </summary>
public PluginGrid()
{
}
/// <summary>
/// Draw all plugins in the plugingrid.
/// </summary>
public void DrawAllPluginsDetails(int width)
{
this.SuspendLayout();
this.Controls.Clear();
this.InitializeComponent();
if (PluginsManager.InstalledPlugins != null)
{
if (PluginsManager.InstalledPlugins.Length == 0)
{
this.lblTextNopluginsinstalled.Visible = true;
}
else
{
this.lblTextNopluginsinstalled.Visible = false;
}
this.btnPluginsStatus = new Button[PluginsManager.InstalledPlugins.Length];
this.tlpnlPlugins = new TableLayoutPanel[PluginsManager.InstalledPlugins.Length];
width -= 150;
if (width < MINWITH)
{
width = MINWITH;
}
for (int i = 0; i < PluginsManager.InstalledPlugins.Length; i++)
{
this.DrawPluginDetails(i, PluginsManager.InstalledPlugins[i], width);
}
}
else
{
this.lblTextNopluginsinstalled.Text = Strings.T("Their are no plugins installed.");
}
this.ResumeLayout();
}
/// <summary>
/// Set the tooltips for this control
/// </summary>
public void SetControlTooltip(ToolTip tooltip)
{
this.tooltip = tooltip;
if (this.btnPluginsStatus.Length != PluginsManager.InstalledPlugins.Length)
{
Log.Write(LogType.exception, "Number of buttons plugins not equal to number of installed buttons, abort SetButtonTooltip");
return;
}
for (int i = 0; i < PluginsManager.InstalledPlugins.Length; i++)
{
this.SetButtonTooltip(this.btnPluginsStatus[i], PluginsManager.IsPluginEnabled(PluginsManager.InstalledPlugins[i]));
}
}
/// <summary>
/// Draw details of a plugin.
/// </summary>
/// <param name="pluginpos">The position of the plugin in allplugins array.</param>
/// <param name="dllfilename">The dll filename of the plugin assemble.</param>
/// <param name="gridwith">The width of the plugingrid control.</param>
private void DrawPluginDetails(int pluginpos, string dllfilename, int gridwith)
{
System.Reflection.Assembly pluginassembly = null;
try
{
pluginassembly = System.Reflection.Assembly.LoadFrom(Path.Combine(Settings.ProgramPluginsFolder, dllfilename));
}
catch (BadImageFormatException badimgformat)
{
Log.Write(LogType.exception, badimgformat.Message);
}
this.tlpnlPlugins[pluginpos] = new System.Windows.Forms.TableLayoutPanel();
Label lblPluginTitle = new System.Windows.Forms.Label();
Label lblTextPluginVersion = new System.Windows.Forms.Label();
Label lblPluginVersion = new System.Windows.Forms.Label();
Label lblTextPluginAuthor = new System.Windows.Forms.Label();
Label lblPluginAuthor = new System.Windows.Forms.Label();
Label lblTextPluginDescription = new System.Windows.Forms.Label();
Label lblPluginDescription = new System.Windows.Forms.Label();
this.btnPluginsStatus[pluginpos] = new Button();
this.tlpnlPlugins[pluginpos].SuspendLayout();
this.tlpnlPlugins[pluginpos].Padding = new Padding(0);
this.tlpnlPlugins[pluginpos].Margin = new Padding(0);
this.tlpnlPlugins[pluginpos].ColumnCount = 3;
this.tlpnlPlugins[pluginpos].ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 22.0000F));
this.tlpnlPlugins[pluginpos].ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 48.0000F));
this.tlpnlPlugins[pluginpos].ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30.0000F));
this.tlpnlPlugins[pluginpos].Controls.Add(lblPluginTitle, 0, 0);
this.tlpnlPlugins[pluginpos].Controls.Add(this.btnPluginsStatus[pluginpos], 1, 0);
this.tlpnlPlugins[pluginpos].Controls.Add(lblTextPluginVersion, 0, 1);
this.tlpnlPlugins[pluginpos].Controls.Add(lblPluginVersion, 1, 1);
this.tlpnlPlugins[pluginpos].Controls.Add(lblTextPluginAuthor, 0, 2);
this.tlpnlPlugins[pluginpos].Controls.Add(lblPluginAuthor, 1, 2);
this.tlpnlPlugins[pluginpos].Controls.Add(lblTextPluginDescription, 0, 3);
this.tlpnlPlugins[pluginpos].Controls.Add(lblPluginDescription, 1, 3);
this.tlpnlPlugins[pluginpos].Location = new System.Drawing.Point(3, pluginpos * 100);
this.tlpnlPlugins[pluginpos].Name = "tlpnlPlugin";
this.tlpnlPlugins[pluginpos].RowCount = 4;
this.tlpnlPlugins[pluginpos].RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
this.tlpnlPlugins[pluginpos].RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 18F));
this.tlpnlPlugins[pluginpos].RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 18F));
this.tlpnlPlugins[pluginpos].RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 23F));
this.tlpnlPlugins[pluginpos].Size = new System.Drawing.Size(gridwith, 99);
this.tlpnlPlugins[pluginpos].TabIndex = 4;
// lblPluginTitle
lblPluginTitle.AutoSize = true;
this.tlpnlPlugins[pluginpos].SetColumnSpan(lblPluginTitle, 2);
lblPluginTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)0);
lblPluginTitle.Location = new System.Drawing.Point(3, 0);
lblPluginTitle.Name = "lblPluginTitle";
lblPluginTitle.Size = new System.Drawing.Size(232, 25);
lblPluginTitle.TabIndex = 1;
if (pluginassembly != null)
{
lblPluginTitle.Text = PluginsManager.GetPluginName(pluginassembly);
}
else
{
lblPluginTitle.Text = dllfilename;
}
// lblTextPluginVersion
lblTextPluginVersion.AutoSize = true;
lblTextPluginVersion.Location = new System.Drawing.Point(3, 37);
lblTextPluginVersion.Name = "lblTextPluginVersion";
lblTextPluginVersion.Size = new System.Drawing.Size(44, 13);
lblTextPluginVersion.TabIndex = 6;
lblTextPluginVersion.Text = Strings.T("version:");
// lblPluginVersion
lblPluginVersion.AutoSize = true;
this.tlpnlPlugins[pluginpos].SetColumnSpan(lblPluginVersion, 2);
lblPluginVersion.Location = new System.Drawing.Point(102, 37);
lblPluginVersion.Name = "lblPluginVersion";
lblPluginVersion.TabIndex = 7;
if (pluginassembly != null)
{
lblPluginVersion.Text = PluginsManager.GetPluginVersion(pluginassembly);
}
if (File.Exists(Path.Combine(Program.GetNewPluginFolder(false), dllfilename)))
{
lblPluginVersion.Text += " " + Strings.T("(restart {0} to update)", Program.AssemblyTitle);
}
// lblTextPluginAuthor
lblTextPluginAuthor.AutoSize = true;
lblTextPluginAuthor.Location = new System.Drawing.Point(3, 53);
lblTextPluginAuthor.Name = "lblTextPluginAuthor";
lblTextPluginAuthor.Size = new System.Drawing.Size(40, 13);
lblTextPluginAuthor.TabIndex = 8;
lblTextPluginAuthor.Text = Strings.T("author:");
// lblPluginAuthor
lblPluginAuthor.AutoSize = true;
this.tlpnlPlugins[pluginpos].SetColumnSpan(lblPluginAuthor, 2);
lblPluginAuthor.Location = new System.Drawing.Point(102, 53);
lblPluginAuthor.Name = "lblPluginAuthor";
lblPluginAuthor.TabIndex = 9;
if (pluginassembly != null)
{
lblPluginAuthor.Text = PluginsManager.GetPluginAuthor(pluginassembly);
}
// lblTextPluginDescription
lblTextPluginDescription.AutoSize = true;
lblTextPluginDescription.Location = new System.Drawing.Point(3, 70);
lblTextPluginDescription.Name = "lblTextPluginDescription";
lblTextPluginDescription.Size = new System.Drawing.Size(68, 13);
lblTextPluginDescription.TabIndex = 10;
lblTextPluginDescription.Text = Strings.T("description:");
// lblPluginDescription
lblPluginDescription.AutoSize = true;
this.tlpnlPlugins[pluginpos].SetColumnSpan(lblPluginDescription, 2);
lblPluginDescription.Location = new System.Drawing.Point(102, 70);
lblPluginDescription.Name = "lblPluginDescription";
lblPluginDescription.TabIndex = 11;
if (pluginassembly != null)
{
lblPluginDescription.Text = PluginsManager.GetPluginDescription(pluginassembly);
}
else
{
lblPluginDescription.Text = Strings.T("Failed Loading the {0} file.", dllfilename);
}
this.btnPluginsStatus[pluginpos].Location = new System.Drawing.Point(230, 20);
this.btnPluginsStatus[pluginpos].Name = "btnTogglePluginStatus" + pluginpos;
this.btnPluginsStatus[pluginpos].Tag = dllfilename;
this.btnPluginsStatus[pluginpos].Size = new System.Drawing.Size(148, 23);
this.btnPluginsStatus[pluginpos].TabIndex = 0;
this.btnPluginsStatus[pluginpos].UseVisualStyleBackColor = true;
this.btnPluginsStatus[pluginpos].Click += new EventHandler(this.PluginGrid_Click);
Controls.Add(this.tlpnlPlugins[pluginpos]);
this.SetPluginStatus(pluginpos, dllfilename);
this.tlpnlPlugins[pluginpos].ResumeLayout(false);
this.tlpnlPlugins[pluginpos].PerformLayout();
}
/// <summary>
/// Plugin toggle enabled.
/// </summary>
/// <param name="sender">Sender object</param>
/// <param name="e">Event argument</param>
private void PluginGrid_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
string dllfilename = (string)btn.Tag;
if (PluginsManager.IsPluginEnabled(dllfilename))
{
PluginsManager.DisablePlugin(dllfilename);
}
else
{
PluginsManager.EnablePlugin(dllfilename);
}
int pos = this.FindPos(dllfilename);
if (pos >= 0)
{
this.SetPluginStatus(pos, dllfilename);
}
PluginsManager.SaveEnabledPlugins();
Program.RestartTrayicon();
}
/// <summary>
/// Update the plugin status if it enabled or disabled.
/// </summary>
/// <param name="pluginpos">The position in tablelayout.</param>
/// <param name="dllfilename">The dll filename to check if it's enabled.</param>
private void SetPluginStatus(int pluginpos, string dllfilename)
{
bool pluginupdateavailable = File.Exists(Path.Combine(Program.GetNewPluginFolder(false), dllfilename));
if (PluginsManager.IsPluginEnabled(dllfilename))
{
if (pluginupdateavailable)
{
this.tlpnlPlugins[pluginpos].BackColor = System.Drawing.Color.Gold;
}
else
{
this.tlpnlPlugins[pluginpos].BackColor = System.Drawing.Color.WhiteSmoke;
}
this.btnPluginsStatus[pluginpos].Text = Strings.T("disable");
this.SetButtonTooltip(this.btnPluginsStatus[pluginpos], true);
}
else
{
if (pluginupdateavailable)
{
this.tlpnlPlugins[pluginpos].BackColor = System.Drawing.Color.SandyBrown;
}
else
{
this.tlpnlPlugins[pluginpos].BackColor = System.Drawing.Color.LightGray;
}
this.btnPluginsStatus[pluginpos].Text = Strings.T("enable");
this.SetButtonTooltip(this.btnPluginsStatus[pluginpos], false);
}
}
/// <summary>
/// Set the tooltip of the enable and disable plugin button.
/// </summary>
/// <param name="btn"></param>
/// <param name="pluginenabled"></param>
private void SetButtonTooltip(Button btn, bool pluginenabled)
{
if (Settings.NotesTooltipsEnabled)
{
if (this.tooltip == null)
{
return;
}
this.tooltip.Active = true;
if (pluginenabled)
{
this.tooltip.SetToolTip(btn, Strings.T("Click to disable this plugin."));
}
else
{
this.tooltip.SetToolTip(btn, Strings.T("Click to enable this plugin."));
}
}
else if (this.tooltip != null)
{
this.tooltip.Active = false;
}
}
/// <summary>
/// Find the position of a plugin dll filename in the tlpnlPlugins
/// </summary>
/// <param name="dllfilename">The dll filename</param>
/// <returns>The position in tlpnlPlugins (counted from the top).</returns>
private int FindPos(string dllfilename)
{
for (int i = 0; i < this.btnPluginsStatus.Length; i++)
{
if (Convert.ToString(this.btnPluginsStatus[i].Tag).Equals(dllfilename, StringComparison.OrdinalIgnoreCase))
{
return i;
}
}
return -1;
}
}
}
MongoDB Logo MongoDB