private void OnAutoTypeFormShown(object sender, EventArgs e) { AutoTypeCtxForm f = sender as AutoTypeCtxForm; ListView lv = Tools.GetControl("m_lvItems", f) as ListView; PluginDebug.AddInfo("Auto-Type entry selection window shown", 0); if ((lv != null) && (lv.Items.Count == 0) && !Program.Config.Integration.AutoTypeAlwaysShowSelDialog) { PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: No entries to display"); f.Close(); return; } if ((lv != null) && (lv.Items.Count == 1) && !Program.Config.Integration.AutoTypeAlwaysShowSelDialog) { lv.Items[0].Selected = true; try { MethodInfo miPIS = f.GetType().GetMethod("ProcessItemSelection", BindingFlags.NonPublic | BindingFlags.Instance); miPIS.Invoke(f, null); PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: Only one entry to be shown"); } catch (Exception ex) { PluginDebug.AddError("Auto-Type Entry Selection window NOT closed", 0, "Reason: Could not process entry", "Details: " + ex.Message); } return; } }
private void OnWindowRemoved(object sender, GwmWindowEventArgs e) { if (m_AT == null) { return; } if (!(e.Form is AutoTypeCtxForm)) { return; } PluginDebug.AddInfo("Auto-Type entry selection window removed", 0); m_AT.Shown -= OnAutoTypeFormShown; ListView lv = Tools.GetControl("m_lvItems", m_AT) as ListView; lv.ColumnWidthChanged -= HandleColumns; lv.Columns.RemoveByKey(Config.DBColumn); lv.Columns.RemoveByKey(Config.PWColumn); UIUtil.ResizeColumns(lv, true); string ColumnWidths = UIUtil.GetColumnWidths(lv); if (ColumnWidths.Length > 0) { KeePass.Program.Config.UI.AutoTypeCtxColumnWidths = ColumnWidths; } m_AT = null; m_SortColumn = null; m_SortOrder = SortOrder.Ascending; m_DBColumnVisible = false; }
private void AddSearchfield(AutoTypeCtxForm f) { var lvShownEntries = Tools.GetControl("m_lvItems", f) as ListView; if (lvShownEntries == null) { PluginDebug.AddError("Could not locate m_lvItems, search-as-you-type field not added"); return; } var c = lvShownEntries.Parent; Label lSearch = new Label(); TextBox tbSearch = new TextBox(); c.Controls.Add(lSearch); c.Controls.Add(tbSearch); lSearch.Text = KeePass.Resources.KPRes.FindEntries; lSearch.AutoSize = true; tbSearch.Left = lvShownEntries.Left + lSearch.Width + DpiUtil.ScaleIntX(10); lSearch.Left = lvShownEntries.Left; tbSearch.Top = lvShownEntries.Top; lSearch.Top = lvShownEntries.Top + tbSearch.Height / 2 - lSearch.Height / 2; tbSearch.Width = lvShownEntries.Width / 2; List <ListViewItem> lvAllEntries = new List <ListViewItem>(lvShownEntries.Items.Cast <ListViewItem>()); tbSearch.Tag = new _SearchAsYouTypeData() { AllEntries = lvAllEntries, ShownEntries = lvShownEntries }; tbSearch.TextChanged += OnFilterSearchResults; int iGap = DpiUtil.ScaleIntY(10); int iHeight = lvShownEntries.Height; tbSearch.Dock = lvShownEntries.Dock = DockStyle.None; lvShownEntries.Top += tbSearch.Height + iGap - 1; lvShownEntries.Height = iHeight - tbSearch.Height - iGap; lvShownEntries.Width = lvShownEntries.Parent.ClientSize.Width - lvShownEntries.Parent.Padding.Left - lvShownEntries.Parent.Padding.Right; }
internal static bool PerformGlobal(List <PwDatabase> lSources, ImageList ilIcons, string strSeq) { if (lSources == null) { Debug.Assert(false); return(false); } if (NativeLib.IsUnix()) { if (!NativeMethods.TryXDoTool(true) && !NativeLib.IsWayland()) { MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer); return(false); } } IntPtr hWnd; string strWindow; try { // hWnd = NativeMethods.GetForegroundWindowHandle(); // strWindow = NativeMethods.GetWindowText(hWnd); NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch (Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } // if(string.IsNullOrEmpty(strWindow)) return false; if (strWindow == null) { Debug.Assert(false); return(false); } if (!IsValidAutoTypeWindow(hWnd, true)) { return(false); } SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List <AutoTypeCtx> lCtxs = new List <AutoTypeCtx>(); PwDatabase pdCurrent = null; bool bExpCanMatch = Program.Config.Integration.AutoTypeExpiredCanMatch; DateTime dtNow = DateTime.UtcNow; EntryHandler eh = delegate(PwEntry pe) { if (!bExpCanMatch && pe.Expires && (pe.ExpiryTime <= dtNow)) { return(true); // Ignore expired entries } List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdCurrent, evQueries.EventID); if (!string.IsNullOrEmpty(strSeq) && (lSeq.Count != 0)) { lCtxs.Add(new AutoTypeCtx(strSeq, pe, pdCurrent)); } else { foreach (string strSeqCand in lSeq) { lCtxs.Add(new AutoTypeCtx(strSeqCand, pe, pdCurrent)); } } return(true); }; foreach (PwDatabase pd in lSources) { if ((pd == null) || !pd.IsOpen) { continue; } pdCurrent = pd; pd.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } GetSequencesForWindowEnd(evQueries); bool bForceDlg = Program.Config.Integration.AutoTypeAlwaysShowSelDialog; if ((lCtxs.Count >= 2) || bForceDlg) { AutoTypeCtxForm dlg = new AutoTypeCtxForm(); dlg.InitEx(lCtxs, ilIcons); bool bOK = (dlg.ShowDialog() == DialogResult.OK); AutoTypeCtx ctx = (bOK ? dlg.SelectedCtx : null); UIUtil.DestroyForm(dlg); if (ctx != null) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch (Exception) { Debug.Assert(false); } int nActDelayMS = TargetActivationDelay; string strWindowT = strWindow.Trim(); // https://sourceforge.net/p/keepass/discussion/329220/thread/3681f343/ // This apparently is only required here (after showing the // auto-type entry selection dialog), not when using the // context menu command in the main window if (strWindowT.EndsWith("Microsoft Edge", StrUtil.CaseIgnoreCmp)) { // 700 skips the first 1-2 characters, // 750 sometimes skips the first character nActDelayMS = 1000; } // Allow target window to handle its activation // (required by some applications, e.g. Edge) Application.DoEvents(); Thread.Sleep(nActDelayMS); Application.DoEvents(); AutoType.PerformInternal(ctx, strWindow); } } else if (lCtxs.Count == 1) { AutoType.PerformInternal(lCtxs[0], strWindow); } return(true); }
public static bool PerformGlobal(List <PwDatabase> vSources, ImageList ilIcons) { Debug.Assert(vSources != null); if (vSources == null) { return(false); } if (KeePassLib.Native.NativeLib.IsUnix()) { if (!NativeMethods.TryXDoTool(true)) { MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer); return(false); } } IntPtr hWnd; string strWindow; try { // hWnd = NativeMethods.GetForegroundWindowHandle(); // strWindow = NativeMethods.GetWindowText(hWnd); NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch (Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } if (string.IsNullOrEmpty(strWindow)) { return(false); } if (!IsValidAutoTypeWindow(hWnd, true)) { return(false); } SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List <AutoTypeCtx> lCtxs = new List <AutoTypeCtx>(); PwDatabase pdCurrent = null; bool bExpCanMatch = Program.Config.Integration.AutoTypeExpiredCanMatch; DateTime dtNow = DateTime.Now; EntryHandler eh = delegate(PwEntry pe) { if (!bExpCanMatch && pe.Expires && (pe.ExpiryTime < dtNow)) { return(true); // Ignore expired entries } List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdCurrent, evQueries.EventID); foreach (string strSeq in lSeq) { lCtxs.Add(new AutoTypeCtx(strSeq, pe, pdCurrent)); } return(true); }; foreach (PwDatabase pwSource in vSources) { if (pwSource.IsOpen == false) { continue; } pdCurrent = pwSource; pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } GetSequencesForWindowEnd(evQueries); bool bForceDlg = Program.Config.Integration.AutoTypeAlwaysShowSelDialog; if ((lCtxs.Count >= 2) || bForceDlg) { AutoTypeCtxForm dlg = new AutoTypeCtxForm(); dlg.InitEx(lCtxs, ilIcons); bool bOK = (dlg.ShowDialog() == DialogResult.OK); AutoTypeCtx ctx = (bOK ? dlg.SelectedCtx : null); UIUtil.DestroyForm(dlg); if (ctx != null) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch (Exception) { Debug.Assert(false); } // Allow target window to handle its activation; // https://sourceforge.net/p/keepass/discussion/329220/thread/3681f343/ Application.DoEvents(); Thread.Sleep(TargetActivationDelay); Application.DoEvents(); AutoType.PerformInternal(ctx, strWindow); } } else if (lCtxs.Count == 1) { AutoType.PerformInternal(lCtxs[0], strWindow); } return(true); }
public static bool PerformGlobal(List <PwDatabase> vSources, ImageList ilIcons) { Debug.Assert(vSources != null); if (vSources == null) { return(false); } if (KeePassLib.Native.NativeLib.IsUnix()) { if (!NativeMethods.TryXDoTool(true)) { MessageService.ShowWarning(KPRes.AutoTypeXDoToolRequiredGlobalVer); return(false); } } IntPtr hWnd; string strWindow; try { // hWnd = NativeMethods.GetForegroundWindowHandle(); // strWindow = NativeMethods.GetWindowText(hWnd); NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true); } catch (Exception) { Debug.Assert(false); hWnd = IntPtr.Zero; strWindow = null; } if (string.IsNullOrEmpty(strWindow)) { return(false); } if (!IsValidAutoTypeWindow(hWnd, true)) { return(false); } SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin( hWnd, strWindow); List <AutoTypeCtx> lCtxs = new List <AutoTypeCtx>(); PwDatabase pdCurrent = null; DateTime dtNow = DateTime.Now; EntryHandler eh = delegate(PwEntry pe) { // Ignore expired entries if (pe.Expires && (pe.ExpiryTime < dtNow)) { return(true); } List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow, pdCurrent, evQueries.EventID); foreach (string strSeq in lSeq) { lCtxs.Add(new AutoTypeCtx(strSeq, pe, pdCurrent)); } return(true); }; foreach (PwDatabase pwSource in vSources) { if (pwSource.IsOpen == false) { continue; } pdCurrent = pwSource; pwSource.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh); } GetSequencesForWindowEnd(evQueries); if (lCtxs.Count == 1) { AutoType.PerformInternal(lCtxs[0], strWindow); } else if (lCtxs.Count > 1) { AutoTypeCtxForm dlg = new AutoTypeCtxForm(); dlg.InitEx(lCtxs, ilIcons); if (dlg.ShowDialog() == DialogResult.OK) { try { NativeMethods.EnsureForegroundWindow(hWnd); } catch (Exception) { Debug.Assert(false); } if (dlg.SelectedCtx != null) { AutoType.PerformInternal(dlg.SelectedCtx, strWindow); } } UIUtil.DestroyForm(dlg); } return(true); }
private void OnWindowAdded(object sender, GwmWindowEventArgs e) { if (!(e.Form is AutoTypeCtxForm)) { return; } if (m_host.MainWindow.DocumentManager.GetOpenDatabases().Count < 1) { return; } m_AT = (AutoTypeCtxForm)e.Form; m_AT.Shown += OnAutoTypeFormShown; PluginDebug.AddInfo("Auto-Type entry selection window added", 0); List <AutoTypeCtx> lCtx = (List <AutoTypeCtx>)Tools.GetField("m_lCtxs", m_AT); if (lCtx == null) { return; } // Adjust content // - Remove entries in expired groups if (Config.ExcludeExpiredGroups) { int PrevCount = lCtx.Count; lCtx.RemoveAll(x => IsGroupExpired(x.Entry.ParentGroup)); PluginDebug.AddInfo("Removed entries in expired groups", 0, "Before: " + PrevCount.ToString(), "After: " + lCtx.Count.ToString()); } // - Adjust sequence to show correct auto-type sequence // - Remove lines that don't contain AAT placeholder if AAT hotkey is used if (AATHotkeyPressed) { int PrevCount = lCtx.Count; lCtx.RemoveAll(x => x.Sequence.IndexOf(Config.Placeholder) < 0); PluginDebug.AddInfo("Removed sequences without AAT placeholder", 0, "Before: " + PrevCount.ToString(), "After: " + lCtx.Count.ToString()); } List <AutoTypeCtx> lUnique = new List <AutoTypeCtx>(); for (int i = lCtx.Count - 1; i >= 0; i--) { lCtx[i].Sequence = AdjustSequence(lCtx[i].Sequence, i == 0); if (lUnique.Find(x => (x.Entry == lCtx[i].Entry) && (x.Sequence == lCtx[i].Sequence)) == null) { lUnique.Add(lCtx[i]); } else { PluginDebug.AddInfo("Remove sequence", 0, "Reason: Duplicate after adjusting auto-type sequences", "Entry: " + lCtx[i].Entry.Uuid.ToString(), "Sequence: " + lCtx[i].Sequence); lCtx.RemoveAt(i); } } //CheckKPAutoTypePasswordHotkey(false); }
private void InitializeAutoTypeListView(object sender, EventArgs e) { AutoTypeCtxForm f = sender as AutoTypeCtxForm; if (f == null) { return; } //AddSearchfield(f); if (m_host.MainWindow.DocumentManager.GetOpenDatabases().Count < 1) { return; } ListView lv = Tools.GetControl("m_lvItems", f) as ListView; PluginDebug.AddInfo("Auto-Type entry selection window shown", 0); if ((lv != null) && (lv.Items.Count == 0) && !KeePass.Program.Config.Integration.AutoTypeAlwaysShowSelDialog) { PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: No entries to display"); f.Close(); return; } if ((lv != null) && (lv.Items.Count == 1) && !KeePass.Program.Config.Integration.AutoTypeAlwaysShowSelDialog) { lv.Items[0].Selected = true; try { m_miProcessItemSelection.Invoke(f, null); PluginDebug.AddInfo("Auto-Type Entry Selection window closed", 0, "Reason: Only one entry to be shown"); } catch (Exception ex) { PluginDebug.AddError("Auto-Type Entry Selection window NOT closed", 0, "Reason: Could not process entry", "Details: " + ex.Message); } return; } if (!Config.AddDBColumn && !Config.ColumnsSortable && !Config.SpecialColumns) { return; } try { if (Config.ColumnsSortable) { lv.HeaderStyle = ColumnHeaderStyle.Clickable; //Recreate groups to ensure the first group is shown correct in case KeeTheme is installed List <ListViewGroup> lvg = new List <ListViewGroup>(); foreach (ListViewGroup g in lv.Groups) { lvg.Add(g); } lv.Groups.Clear(); foreach (ListViewGroup g in lvg) { lv.Groups.Add(g); } lv.ColumnClick += SortColumns; Button bTools = (Button)Tools.GetControl("m_btnTools", f); if (bTools != null) { CheckBox cbShowGroups = new CheckBox(); cbShowGroups.Name = "cbAAT_ShowGroups"; cbShowGroups.Checked = Config.ColumnsRememberSorting && Config.ColumnsSortGrouping; cbShowGroups.Text = PluginTranslate.AATFormShowGroups; cbShowGroups.AutoSize = true; f.Controls.Add(cbShowGroups); bTools.Parent.Controls.Add(cbShowGroups); cbShowGroups.Top = bTools.Bottom - cbShowGroups.Height; cbShowGroups.Left = bTools.Left + bTools.Width + 5; cbShowGroups.CheckedChanged += AutoTypeForm_ShowGroups_CheckedChanged; } int s = (int)Config.ColumnsSortColumn; if (Config.ColumnsRememberSorting && (s != 0) && (Math.Abs(s) <= lv.Columns.Count)) { SortColumns(lv, new ColumnClickEventArgs(Math.Abs(s) - 1)); if (((s > 0) && (m_SortOrder != SortOrder.Ascending)) || ((s < 0) && (m_SortOrder != SortOrder.Descending))) { SortColumns(lv, new ColumnClickEventArgs(Math.Abs(s) - 1)); } } } if (Config.SpecialColumns && !KeePassLib.Native.NativeLib.IsUnix()) { lv.MouseClick += CellClick; lv.ColumnWidthChanged += HandleColumns; HandleColumns(lv, null); } if (Config.AddDBColumn) { List <AutoTypeCtx> lEntries = (List <AutoTypeCtx>)Tools.GetField("m_lCtxs", f); string db1 = lEntries[0].Database.IOConnectionInfo.Path; if (lEntries.Any(x => x.Database.IOConnectionInfo.Path != db1)) //foreach (AutoTypeCtx entry in lEntries) //{ //if (entry.Database.IOConnectionInfo.Path != db1) { m_DBColumnVisible = true; if (!Config.SpecialColumns) { lv.ColumnWidthChanged += HandleColumns; } HandleColumns(lv, null); Button btnTools = (Button)Tools.GetField("m_btnTools", f); btnTools.Click += OnColumnMenuOpening; //break; } //} } } catch (Exception) { } }