Inheritance: System.Windows.Forms.Form
Exemplo n.º 1
0
        private void OnEntryDuplicate(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgSelected = GetSelectedGroup();

            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            DuplicationForm dlg = new DuplicationForm();
            if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;

            PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
            foreach(PwEntry pe in vSelected)
            {
                PwEntry peNew = pe.CloneDeep();
                peNew.SetUuid(new PwUuid(true), true); // Create new UUID

                dlg.ApplyTo(peNew, pe, pd);

                Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
                PwGroup pg = (pe.ParentGroup ?? pgSelected);
                if((pg == null) && (pd != null)) pg = pd.RootGroup;
                if(pg == null) continue;

                pg.AddEntry(peNew, true, true);
                vNewEntries.Add(peNew);
            }

            AddEntriesToList(vNewEntries);
            SelectEntries(vNewEntries, true, true);

            // if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
            //	m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
            // else EnsureVisibleSelected(true);
            EnsureVisibleSelected(true); // Show all copies if possible
            EnsureVisibleSelected(false); // Ensure showing the first

            UpdateUIState(true, m_lvEntries);
        }
Exemplo n.º 2
0
        private void OnEntryDuplicate(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pgSelected = GetSelectedGroup();

            PwEntry[] vSelected = GetSelectedEntries();
            if((vSelected == null) || (vSelected.Length == 0)) return;

            DuplicationForm dlg = new DuplicationForm();
            if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;

            PwObjectList<PwEntry> vNewEntries = new PwObjectList<PwEntry>();
            foreach(PwEntry pe in vSelected)
            {
                PwEntry peNew = pe.CloneDeep();
                peNew.SetUuid(new PwUuid(true), true); // Create new UUID

                if(dlg.AppendCopyToTitles && (pd != null))
                {
                    string strTitle = peNew.Strings.ReadSafe(PwDefs.TitleField);
                    peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
                        pd.MemoryProtection.ProtectTitle, strTitle + " - " +
                        KPRes.CopyOfItem));
                }

                if(dlg.ReplaceDataByFieldRefs && (pd != null))
                {
                    string strUser = @"{REF:U@I:" + pe.Uuid.ToHexString() + @"}";
                    peNew.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                        pd.MemoryProtection.ProtectUserName, strUser));

                    string strPw = @"{REF:P@I:" + pe.Uuid.ToHexString() + @"}";
                    peNew.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                        pd.MemoryProtection.ProtectPassword, strPw));
                }

                Debug.Assert(pe.ParentGroup == peNew.ParentGroup);
                PwGroup pg = (pe.ParentGroup ?? pgSelected);
                if((pg == null) && (pd != null)) pg = pd.RootGroup;
                if(pg == null) continue;

                pg.AddEntry(peNew, true, true);
                vNewEntries.Add(peNew);
            }

            AddEntriesToList(vNewEntries);
            SelectEntries(vNewEntries, true, false);

            if(!m_lvEntries.ShowGroups && (m_lvEntries.Items.Count >= 1))
                m_lvEntries.EnsureVisible(m_lvEntries.Items.Count - 1);
            else EnsureVisibleSelected(true);

            UpdateUIState(true, m_lvEntries);
        }
Exemplo n.º 3
0
        private void OnGroupsDuplicate(object sender, EventArgs e)
        {
            PwGroup pgBase = GetSelectedGroup();
            if(pgBase == null) { Debug.Assert(false); return; }
            PwGroup pgParent = pgBase.ParentGroup;
            if(pgParent == null) { Debug.Assert(false); return; }

            DuplicationForm dlg = new DuplicationForm();
            if(UIUtil.ShowDialogAndDestroy(dlg) != DialogResult.OK) return;

            PwDatabase pd = m_docMgr.ActiveDatabase;
            PwGroup pg = pgBase.CloneDeep();

            pg.Uuid = new PwUuid(true);
            pg.CreateNewItemUuids(true, true, true);
            pg.TakeOwnership(true, true, true);

            pg.ParentGroup = pgParent;
            int iBase = pgParent.Groups.IndexOf(pgBase);
            if(iBase < 0) { Debug.Assert(false); iBase = (int)pgParent.Groups.UCount; }
            else ++iBase;
            pgParent.Groups.Insert((uint)iBase, pg);

            PwObjectList<PwEntry> lBase = pgBase.GetEntries(true);
            PwObjectList<PwEntry> lNew = pg.GetEntries(true);
            if((lBase != null) && (lNew != null) && (lBase.UCount == lNew.UCount))
            {
                for(uint u = 0; u < lBase.UCount; ++u)
                    dlg.ApplyTo(lNew.GetAt(u), lBase.GetAt(u), pd);
            }
            else { Debug.Assert(false); }

            UpdateUI(false, null, true, pg, true, null, true);
        }