private void reload_menu()
{
int i = pmPasswords.Items.Count - 1;
pmPasswords.SuspendLayout();
while (i >= 5) {
pmPasswords.Items.Remove(pmPasswords.Items[i]);
i--;
}
miNoPasswords.Visible = true;
miNoPasswords.Enabled = false;
miNoPasswords.Image = null;
if (Host.MainWindow.IsFileLocked(null)) {
miNoPasswords.Text = KPRes.LockMenuUnlock;
miNoPasswords.ToolTipText = "The current database is locked.";
miNoPasswords.Enabled = true;
toolStripTextSearch.Visible = false;
miNoPasswords.Image = ilIcons.Images[6];
//reset "LastOne"-Entry as soon as database is locked
LastOne.Visible = false;
LastOne.Text = "LastOne";
LastOne.DropDownItems.Clear();
}
else
if ((Host.Database != null) && (Host.Database.IsOpen))
{
toolStripTextSearch.Visible = FOptions.showSearch;
LastOne.Visible = FOptions.showLastOne && LastOne.Text != "LastOne";
PwGroup start_group = Host.Database.RootGroup;
if (start_group != null && !string.IsNullOrEmpty(FOptions.startGroupUUID)) {
PwObjectList<PwGroup> all_groups = Host.Database.RootGroup.GetGroups(true);
foreach (PwGroup group in all_groups) {
if (group.Uuid.ToHexString() == FOptions.startGroupUUID) {
start_group = group;
break;
}
}
if (start_group.Entries.UCount <= 0 && start_group.Groups.UCount <= 0)
start_group = Host.Database.RootGroup;
}
//on default LastOne is visible
PwEntry last_entry = LastOne.Tag as PwEntry;
bool last_entry_ok = false;
if (last_entry != null) {
PwGroup tmp_grp = last_entry.ParentGroup;
while (tmp_grp != null) {
if (tmp_grp == start_group) {
last_entry_ok = true;
break;
}
if (tmp_grp == Host.Database.RootGroup)
break;
tmp_grp = tmp_grp.ParentGroup;
}
}
if (!last_entry_ok)
LastOne.Visible = false;
if ((start_group != null) && ((start_group.Entries.UCount > 0) || (start_group.Groups.UCount > 0))) {
AddGroupToMenu(null, start_group);
miNoPasswords.Visible = false;
}
else {
toolStripTextSearch.Visible = LastOne.Visible = false;
miNoPasswords.Text = "-= No passwords =-";
miNoPasswords.ToolTipText = "There are no passwords defined.\nOpen KeePass and create some new passwords.";
}
}
else {
toolStripTextSearch.Visible = LastOne.Visible = false;
miNoPasswords.Text = "-= No database open =-";
miNoPasswords.ToolTipText = "There is no opened database.\nPlease open existing or create new database.";
}
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
pmPasswords.ResumeLayout();
}