public void AddMenuItem(List <char> lAvailKeys) { if (m_tsmi != null) { Debug.Assert(false); return; } string strNameAccel = StrUtil.AddAccelerator( StrUtil.EncodeMenuText(m_strName), lAvailKeys); Debug.Assert(StrUtil.EncodeMenuText(KPRes.OpenWith) == KPRes.OpenWith); string strText = KPRes.OpenWith.Replace(@"{PARAM}", strNameAccel); m_tsmi = m_dynMenu.AddItem(strText, m_imgIcon, this); try { string strTip = m_strPath; if (strTip.StartsWith("cmd://", StrUtil.CaseIgnoreCmp)) { strTip = strTip.Substring(6); } if (strTip.Length != 0) { m_tsmi.ToolTipText = strTip; } } catch (Exception) { Debug.Assert(false); } // Too long? }
private void OnEntryContextMenuOpening(object sender, CancelEventArgs e) { ctxEntryShowQRCode.Visible = false; if (!host.Database.IsOpen) { return; } if (host.MainWindow.GetSelectedEntriesCount() != 1) { return; } var pe = host.MainWindow.GetSelectedEntry(true); if (pe == null) { return; } dynQRCodes.Clear(); var items = new List <Tuple <string, string> >(); foreach (var kvp in pe.Strings) { if (kvp.Value.IsEmpty) { continue; } items.Add(Tuple.Create( StrUtil.EncodeMenuText(TryTranslateKey(kvp.Key)), kvp.Key )); } foreach (var kv in items.OrderBy(t => t.Item1)) { dynQRCodes.AddItem( kv.Item1, Properties.Resources.icon, kv.Item2 ); } ctxEntryShowQRCode.Visible = true; }
private void OnDropDownOpening(object sender, EventArgs e) { var item = (ToolStripMenuItem)sender; var dynamicMenu = (DynamicMenu)item.Tag; dynamicMenu.Clear(); item.DropDownItems.Clear(); if (!host.Database.IsOpen) { return; } if (host.MainWindow.GetSelectedEntriesCount() != 1) { return; } var pe = host.MainWindow.GetSelectedEntry(true); if (pe == null) { return; } var items = new List <Tuple <string, string> >(); foreach (var kvp in pe.Strings) { if (kvp.Value.IsEmpty) { continue; } items.Add(Tuple.Create( StrUtil.EncodeMenuText(TryTranslateKey(kvp.Key)), kvp.Key )); } foreach (var kv in items.OrderBy(t => t.Item1)) { dynamicMenu.AddItem( kv.Item1, Properties.Resources.icon, kv.Item2 ); } }
private void UpdateMenu(object oContainer) { ToolStripMenuItem tsmiContainer = (oContainer as ToolStripMenuItem); if (tsmiContainer == null) { Debug.Assert(false); return; } if (!m_lContainers.Contains(tsmiContainer)) { Debug.Assert(false); return; } tsmiContainer.DropDown.SuspendLayout(); // Verify that the popup arrow has been drawn (i.e. items existed) Debug.Assert(tsmiContainer.DropDownItems.Count > 0); ReleaseMenuItems(); tsmiContainer.DropDownItems.Clear(); uint uAccessKey = 1, uNull = 0; if (m_vItems.Count > 0) { foreach (KeyValuePair <string, object> kvp in m_vItems) { AddMenuItem(tsmiContainer, MruMenuItemType.Item, StrUtil.EncodeMenuText(kvp.Key), null, kvp.Value, true, ref uAccessKey); } tsmiContainer.DropDownItems.Add(new ToolStripSeparator()); AddMenuItem(tsmiContainer, MruMenuItemType.Clear, KPRes.ClearMru, Properties.Resources.B16x16_EditDelete, null, true, ref uNull); } else { AddMenuItem(tsmiContainer, MruMenuItemType.None, "(" + KPRes.Empty + ")", null, null, false, ref uNull); } tsmiContainer.DropDown.ResumeLayout(true); }
private static void AddItem(PwEntry pe) { if (pe == null) { Debug.Assert(false); return; } string strText = StrUtil.EncodeMenuText(pe.Strings.ReadSafe( PwDefs.TitleField)); ToolStripMenuItem tsmi = new ToolStripMenuItem(strText); tsmi.Tag = pe; tsmi.Click += OnMenuExecute; Image img = null; PwDatabase pd = Program.MainForm.DocumentManager.SafeFindContainerOf(pe); if (pd != null) { if (!pe.CustomIconUuid.Equals(PwUuid.Zero)) { img = DpiUtil.GetIcon(pd, pe.CustomIconUuid); } if (img == null) { try { img = Program.MainForm.ClientIcons.Images[(int)pe.IconId]; } catch (Exception) { Debug.Assert(false); } } } if (img == null) { img = Properties.Resources.B16x16_KGPG_Key1; } tsmi.Image = img; m_btnItemsHost.DropDownItems.Add(tsmi); m_vToolStripItems.Add(tsmi); }
private void OnFormLoad(object sender, EventArgs e) { if (m_pwDatabase == null) { Debug.Assert(false); throw new InvalidOperationException(); } if (m_pgStorage == null) { Debug.Assert(false); throw new InvalidOperationException(); } GlobalWindowManager.AddWindow(this); BannerFactory.CreateBannerEx(this, m_bannerImage, KeePass.Properties.Resources.B48x48_Wizard, KPRes.TanWizard, KPRes.TanWizardDesc); this.Icon = AppIcons.Default; this.Text = KPRes.TanWizard; Debug.Assert(!m_lblToGroup.AutoSize); // For RTL support if (!string.IsNullOrEmpty(m_pgStorage.Name)) { m_lblToGroup.Text += ": " + StrUtil.EncodeMenuText( m_pgStorage.Name) + "."; } else { m_lblToGroup.Text += "."; } m_tbTanChars.Text = Program.Config.Defaults.TanCharacters; UIUtil.AccSetName(m_numTANsIndex, m_cbNumberTans); EnableControlsEx(); }
private void UpdateMenu(object sender, EventArgs e) { if (m_lv == null) { Debug.Assert(false); return; } DeleteMenuItems(); IComparer icSorter = m_lv.ListViewItemSorter; ListSorter ls = ((icSorter != null) ? (icSorter as ListSorter) : null); if (ls != null) { m_iCurSortColumn = ls.Column; m_bCurSortAsc = (ls.Order != SortOrder.Descending); if ((ls.Order == SortOrder.None) || (m_iCurSortColumn >= m_lv.Columns.Count)) { m_iCurSortColumn = -1; } } else { m_iCurSortColumn = -1; } m_tsmiNoSort = new ToolStripMenuItem(KPRes.NoSort); if (m_iCurSortColumn < 0) { UIUtil.SetRadioChecked(m_tsmiNoSort, true); } m_tsmiNoSort.Click += this.OnNoSort; m_tsmiMenu.DropDownItems.Add(m_tsmiNoSort); m_tssSep0 = new ToolStripSeparator(); m_tsmiMenu.DropDownItems.Add(m_tssSep0); m_vColumns = new List <ToolStripMenuItem>(); foreach (ColumnHeader ch in m_lv.Columns) { string strText = (ch.Text ?? string.Empty); strText = StrUtil.EncodeMenuText(strText); ToolStripMenuItem tsmi = new ToolStripMenuItem(strText); if (ch.Index == m_iCurSortColumn) { UIUtil.SetRadioChecked(tsmi, true); } tsmi.Click += this.OnSortColumn; m_vColumns.Add(tsmi); m_tsmiMenu.DropDownItems.Add(tsmi); } m_tssSep1 = new ToolStripSeparator(); m_tsmiMenu.DropDownItems.Add(m_tssSep1); m_tsmiAsc = new ToolStripMenuItem(KPRes.Ascending); if ((m_iCurSortColumn >= 0) && m_bCurSortAsc) { UIUtil.SetRadioChecked(m_tsmiAsc, true); } m_tsmiAsc.Click += this.OnSortAscDesc; if (m_iCurSortColumn < 0) { m_tsmiAsc.Enabled = false; } m_tsmiMenu.DropDownItems.Add(m_tsmiAsc); m_tsmiDesc = new ToolStripMenuItem(KPRes.Descending); if ((m_iCurSortColumn >= 0) && !m_bCurSortAsc) { UIUtil.SetRadioChecked(m_tsmiDesc, true); } m_tsmiDesc.Click += this.OnSortAscDesc; if (m_iCurSortColumn < 0) { m_tsmiDesc.Enabled = false; } m_tsmiMenu.DropDownItems.Add(m_tsmiDesc); }
private void OnTrayOpening(object sender, EventArgs e) { PluginDebug.AddInfo("Tray setup: Start", 0); m_TrayMenu.DropDownItems.Clear(); List <PwDatabase> lDB = m_host.MainWindow.DocumentManager.GetOpenDatabases(); SearchParameters sp = new SearchParameters(); sp.ExcludeExpired = !Program.Config.Integration.AutoTypeExpiredCanMatch; //exclude expired entries only if they can not match sp.SearchInStringNames = true; Dictionary <string, PwObjectList <PwEntry> > dEntries = new Dictionary <string, PwObjectList <PwEntry> >(); foreach (PwDatabase db in lDB) { string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path); if (!string.IsNullOrEmpty(db.Name)) { dbName = db.Name + " (" + dbName + ")"; } PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>(); if (Config.UseDBForOTPSeeds(db)) { sp.SearchString = OTPDAO.OTPHandler_DB.DBNAME; } else { sp.SearchString = Config.OTPFIELD; // Config.SEED + " " + Config.SETTINGS; } db.RootGroup.SearchEntries(sp, entries); PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.UCount.ToString()); if ((entries == null) || (entries.UCount == 0)) { continue; } //Ignore deleted entries PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null; if (pgRecycle != null) { for (int i = (int)entries.UCount - 1; i >= 0; i--) { PwEntry pe = entries.GetAt((uint)i); if (pe.IsContainedIn(pgRecycle)) { entries.Remove(pe); } } } entries.Sort(SortEntries); dEntries.Add(dbName, entries); } foreach (var kvp in dEntries) { ToolStripMenuItem parent = null; //If entries of only one DB are found don't include the DB as additional menu level if (dEntries.Count == 1) { parent = m_TrayMenu; } else { parent = new ToolStripMenuItem(kvp.Key); m_TrayMenu.DropDownItems.Add(parent); } foreach (PwEntry pe in kvp.Value) { ToolStripMenuItem entry = new ToolStripMenuItem(); string[] text = GetTrayText(pe); PluginDebug.AddInfo("Tray setup: Add entry", 0, "Uuid: " + text[2]); // Do NOT add username and entry title to debugfile if (text[0] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(string.Format(PluginTranslate.User, text[1])); } else if (text[1] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(text[0]); } else { entry.Text = StrUtil.EncodeMenuText(text[0] + " (" + text[1] + ")"); } entry.Name = "KPOTP_" + pe.Uuid.ToString(); entry.Click += OnOTPTray; entry.Tag = pe; parent.DropDownItems.Add(entry); } } m_TrayMenu.Enabled = dEntries.Count > 0; m_TrayMenu.Text = m_TrayMenu.Enabled ? PluginTranslate.OTPCopyTrayEntries : PluginTranslate.OTPCopyTrayNoEntries; }
public static void MakeTagsButton(Button btn, TextBox tb, ToolTip tt, PwGroup pgParent, PwGroup pgTagsSource) { if ((btn == null) || (tb == null)) { Debug.Assert(false); return; } Debug.Assert(tt != null); Image img = UIUtil.CreateDropDownImage(Properties.Resources.B16x16_KNotes); UIUtil.SetButtonImage(btn, img, true); UIUtil.SetToolTip(tt, btn, KPRes.TagsAddRemove, true); CustomContextMenuStripEx ctx = null; Font fItalic = null; btn.Click += delegate(object sender, EventArgs e) { if (ctx == null) { ctx = new CustomContextMenuStripEx(); fItalic = FontUtil.CreateFont(ctx.Font, FontStyle.Italic); } List <string> lCur = StrUtil.StringToTags(tb.Text); Dictionary <string, bool> dCur = new Dictionary <string, bool>(); foreach (string strTag in lCur) { dCur[strTag] = true; } List <string> lParent = ((pgParent != null) ? pgParent.GetTagsInherited(true) : new List <string>()); Dictionary <string, bool> dParent = new Dictionary <string, bool>(); foreach (string strTag in lParent) { dParent[strTag] = true; } List <string> lAll = new List <string>(lCur); if (pgTagsSource != null) { lAll.AddRange(pgTagsSource.BuildEntryTagsList(false, true)); StrUtil.NormalizeTags(lAll); } List <ToolStripItem> lMenuItems = new List <ToolStripItem>(); if (lAll.Count == 0) { ToolStripMenuItem tsmi = new ToolStripMenuItem( StrUtil.EncodeMenuText("(" + KPRes.TagsNotFound + ")")); tsmi.Enabled = false; lMenuItems.Add(tsmi); } else { for (int i = 0; i < lAll.Count; ++i) { string strTag = lAll[i]; // Used in Click handler bool bHasTag = dCur.ContainsKey(strTag); bool bInh = dParent.ContainsKey(strTag); string strSuffix = string.Empty; if (bInh) { strSuffix = " (" + KPRes.Inherited + ")"; } ToolStripMenuItem tsmi = new ToolStripMenuItem( StrUtil.EncodeMenuText(strTag + strSuffix)); UIUtil.SetChecked(tsmi, bHasTag); if (bInh) { tsmi.Font = fItalic; } tsmi.Click += delegate(object senderT, EventArgs eT) { if (bHasTag) { lCur.Remove(strTag); } else { lCur.Add(strTag); StrUtil.NormalizeTags(lCur); } tb.Text = StrUtil.TagsToString(lCur, true); }; lMenuItems.Add(tsmi); } } ctx.Items.Clear(); ctx.Items.AddRange(lMenuItems.ToArray()); ctx.ShowEx(btn); }; }
private static List <ToolStripItem> CreateGroupItems(PwGroup pg) { List <ToolStripItem> l = new List <ToolStripItem>(); if (pg == null) { Debug.Assert(false); return(l); } if (g_tsiHost == null) { Debug.Assert(false); return(l); } bool bGroups = (pg.Groups.UCount != 0); bool bEntries = (pg.Entries.UCount != 0); if (!bGroups && !bEntries) { l.Add(CreateEmptyItem()); return(l); } foreach (PwGroup pgSub in pg.Groups) { string strText = StrUtil.EncodeMenuText(pgSub.Name); ToolStripMenuItem tsmi = new ToolStripMenuItem(strText); tsmi.Image = GetImage(pgSub.IconId, pgSub.CustomIconUuid); tsmi.Tag = pgSub; ToolStripMenuItem tsmiDynPlh = new ToolStripMenuItem("<>"); tsmi.DropDownItems.Add(tsmiDynPlh); // Ensure popup arrow PwGroup pgSubCur = pgSub; // Copy the ref., as pgSub changes tsmi.DropDownOpening += delegate(object sender, EventArgs e) { Debug.Assert(object.ReferenceEquals(sender, tsmi)); Debug.Assert(object.ReferenceEquals(tsmi.Tag, pgSubCur)); ToolStripItemCollection tsic = tsmi.DropDownItems; if ((tsic.Count == 1) && (tsic[0] == tsmiDynPlh)) { BlockLayout(true); tsic.Clear(); tsic.AddRange(CreateGroupItems(pgSubCur).ToArray()); BlockLayout(false); } }; l.Add(tsmi); } if (bGroups && bEntries) { l.Add(new ToolStripSeparator()); } foreach (PwEntry pe in pg.Entries) { string strText = StrUtil.EncodeMenuText(pe.Strings.ReadSafe( PwDefs.TitleField)); ToolStripMenuItem tsmi = new ToolStripMenuItem(strText); tsmi.Image = GetImage(pe.IconId, pe.CustomIconUuid); tsmi.Tag = pe; tsmi.Click += OnMenuExecute; l.Add(tsmi); } return(l); }
private List <ToolStripItem> ConstructMenuItems() { List <ToolStripItem> l = new List <ToolStripItem>(); List <char> lAvailKeys = new List <char>(PwCharSet.MenuAccels); ProtectedString ps = GetPassword(); GFunc <string, Image, EventHandler, object, ToolStripMenuItem> fAdd = delegate(string strText, Image img, EventHandler ehClick, object oTag) { string str = StrUtil.EncodeMenuText(strText ?? string.Empty); str = StrUtil.AddAccelerator(str, lAvailKeys); ToolStripMenuItem tsmi = new ToolStripMenuItem(str); if (img != null) { tsmi.Image = img; } if (ehClick != null) { tsmi.Click += ehClick; } if (oTag != null) { tsmi.Tag = oTag; } l.Add(tsmi); return(tsmi); }; fAdd(KPRes.PwGenOpen, Properties.Resources.B16x16_Key_New, this.OnGenOpen, null); l.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiDerive = fAdd(GenDeriveFromPrevious, Properties.Resources.B16x16_CompFile, this.OnGenDeriveFromPrevious, null); if (IsMultipleValues(ps)) { tsmiDerive.Enabled = false; } fAdd(GenAuto, Properties.Resources.B16x16_FileNew, this.OnGenAuto, null); bool bHideBuiltIn = ((Program.Config.UI.UIFlags & (ulong)AceUIFlags.HideBuiltInPwGenPrfInEntryDlg) != 0); bool bFirst = true; foreach (PwProfile prf in PwGeneratorUtil.GetAllProfiles(true)) { if (prf == null) { Debug.Assert(false); continue; } if (bHideBuiltIn && PwGeneratorUtil.IsBuiltInProfile(prf.Name)) { continue; } if (bFirst) { l.Add(new ToolStripSeparator()); bFirst = false; } fAdd(prf.Name, Properties.Resources.B16x16_KOrganizer, this.OnGenProfile, prf); } return(l); }
private void OnTrayOpening(object sender, EventArgs e) { PluginDebug.AddInfo("Tray setup: Start", 0); m_TrayMenu.DropDownItems.Clear(); List <PwDatabase> lDB = m_host.MainWindow.DocumentManager.GetOpenDatabases(); Dictionary <string, List <PwEntry> > dEntries = new Dictionary <string, List <PwEntry> >(); DateTime dtExpired = DateTime.UtcNow; foreach (PwDatabase db in lDB) { string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path); if (!string.IsNullOrEmpty(db.Name)) { dbName = db.Name + " (" + dbName + ")"; } string sSearch = Config.UseDBForOTPSeeds(db) ? OTPDAO.OTPHandler_DB.DBNAME : Config.OTPFIELD; var entries = db.RootGroup.GetEntries(true).Where(x => x.Strings.Exists(sSearch)).ToList(); if (!Program.Config.Integration.AutoTypeExpiredCanMatch) // Remove expired entries { entries = entries.Where(x => !x.Expires || x.ExpiryTime >= dtExpired).ToList(); } PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.Count.ToString()); if (entries.Count == 0) { continue; } //Ignore deleted entries PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null; if (pgRecycle != null) { for (int i = entries.Count - 1; i >= 0; i--) { PwEntry pe = entries[i]; if (pe.IsContainedIn(pgRecycle)) { entries.Remove(pe); } } } entries.Sort(SortEntries); dEntries.Add(dbName, entries); } foreach (var kvp in dEntries) { ToolStripMenuItem parent = null; //If entries of only one DB are found don't include the DB as additional menu level if (dEntries.Count == 1) { parent = m_TrayMenu; } else { parent = new ToolStripMenuItem(kvp.Key); m_TrayMenu.DropDownItems.Add(parent); } foreach (PwEntry pe in kvp.Value) { ToolStripMenuItem entry = new ToolStripMenuItem(); string[] text = GetTrayText(pe); PluginDebug.AddInfo("Tray setup: Add entry", 0, "Uuid: " + text[2]); // Do NOT add username and entry title to debugfile if (text[0] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(string.Format(PluginTranslate.User, text[1])); } else if (text[1] == string.Empty) { entry.Text = StrUtil.EncodeMenuText(text[0]); } else { entry.Text = StrUtil.EncodeMenuText(text[0] + " (" + text[1] + ")"); } entry.Name = "KPOTP_" + pe.Uuid.ToString(); entry.Click += OnOTPTray; entry.Tag = pe; parent.DropDownItems.Add(entry); } } m_TrayMenu.Enabled = dEntries.Count > 0; m_TrayMenu.Text = m_TrayMenu.Enabled ? PluginTranslate.OTPCopyTrayEntries : PluginTranslate.OTPCopyTrayNoEntries; }