Exemplo n.º 1
0
        private void NavigateToSelectedEntry(ListViewForm dlg, bool CalledFromSearchForm)
        {
            PwGroup pg = dlg.ResultGroup as PwGroup;             //parent group of selected entry
            PwEntry pe = dlg.ResultItem as PwEntry;

            if (pe == null)             //try getting the virtual group for the selected entries database
            {
                object[] oEntryAndGroup = dlg.ResultItem as object[];
                if ((oEntryAndGroup != null) && (oEntryAndGroup.Length == 2))
                {
                    pe = oEntryAndGroup[0] as PwEntry;
                    pg = oEntryAndGroup[1] as PwGroup;
                }
            }
            if (pe != null)
            {
                ActivateDB(pe);
            }
            if ((pg == null) && (pe == null))
            {
                pg = (dlg.ResultItem as PwGroup);
            }
            if ((pg != null) || (pe != null))
            {
                if (pg != null)
                {
                    PwDocument doc = null;
                    if (pe == null)
                    {
                        doc = m_host.MainWindow.DocumentManager.FindDocument(m_host.MainWindow.DocumentManager.SafeFindContainerOf(pg.Entries.GetAt(0)));
                    }
                    else
                    {
                        doc = m_host.MainWindow.DocumentManager.FindDocument(m_host.MainWindow.DocumentManager.SafeFindContainerOf(pe));
                    }
                    bool bCleanUpDone = false;
                    for (int i = (int)pg.Entries.UCount - 1; i >= 0; i--)
                    {
                        if (doc != m_host.MainWindow.DocumentManager.FindDocument(m_host.MainWindow.DocumentManager.SafeFindContainerOf(pg.Entries.GetAt((uint)i))))
                        {
                            bCleanUpDone = true;
                            pg.Entries.RemoveAt((uint)i);
                        }
                    }
                    if (bCleanUpDone && !CalledFromSearchForm)
                    {
                        ShowMultiDBInfo(CalledFromSearchForm);
                    }
                    if (pg != null)
                    {
                        pe = pg.Entries.GetAt(0);
                        foreach (KeyValuePair <PwDatabase, PwGroup> kvp in m_dDBGroups)
                        {
                            if (kvp.Value.FindEntry(pe.Uuid, true) != null)
                            {
                                pg = kvp.Value;
                                break;
                            }
                        }
                    }
                    m_host.MainWindow.UpdateUI(false, doc, false, null, true, pg, false, m_lvEntries);
                }
                else
                {
                    PwDocument doc = m_host.MainWindow.DocumentManager.FindDocument(m_host.MainWindow.DocumentManager.SafeFindContainerOf(pe));
                    m_host.MainWindow.UpdateUI(false, doc, true, pe.ParentGroup, true, null, false, m_lvEntries);
                }

                MethodInfo mi = null;
                if (pe != null)
                {
                    KeePassLib.Collections.PwObjectList <PwEntry> lSel = new KeePassLib.Collections.PwObjectList <PwEntry>();
                    lSel.Add(pe);
                    m_host.MainWindow.SelectEntries(lSel, true, true);
                    mi = m_host.MainWindow.GetType().GetMethod("EnsureVisibleSelected", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (mi != null)
                    {
                        mi.Invoke(m_host.MainWindow, new object[] { false });
                    }
                }
                else
                {
                    mi = m_host.MainWindow.GetType().GetMethod("SelectFirstEntryIfNoneSelected", BindingFlags.Instance | BindingFlags.NonPublic);
                    if (mi != null)
                    {
                        mi.Invoke(m_host.MainWindow, null);
                    }
                }

                mi = m_host.MainWindow.GetType().GetMethod("UpdateUIState", BindingFlags.Instance | BindingFlags.NonPublic, null,
                                                           new Type[] { typeof(bool) }, null);
                if (mi != null)
                {
                    mi.Invoke(m_host.MainWindow, new object[] { false });
                }
            }
            m_dDBGroups.Clear();
        }