InitEx() публичный Метод

public InitEx ( PwEntry pwEntry, PwEditMode pwMode, KeePassLib.PwDatabase pwDatabase, ImageList ilIcons, bool bShowAdvancedByDefault, bool bSelectFullTitle ) : void
pwEntry PwEntry
pwMode PwEditMode
pwDatabase KeePassLib.PwDatabase
ilIcons System.Windows.Forms.ImageList
bShowAdvancedByDefault bool
bSelectFullTitle bool
Результат void
Пример #1
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if(peTemplate == null) { Debug.Assert(false); return; }

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if(pd == null) { Debug.Assert(false); return; }
            if(pd.IsOpen == false) { Debug.Assert(false); return; }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null) pgContainer = pd.RootGroup;

            PwEntry pe = peTemplate.Duplicate();

            if(EntryTemplates.EntryCreating != null)
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                    peTemplate.CloneDeep(), pe));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                false, true);

            if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                MainForm mf = Program.MainForm;
                if(mf != null)
                {
                    mf.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                        true, null, true);

                    PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
                    vSelect.Add(pe);
                    mf.SelectEntries(vSelect, true, true);

                    mf.EnsureVisibleEntry(pe.Uuid);
                    mf.UpdateUI(false, null, false, null, false, null, false);
                }
                else { Debug.Assert(false); }

                if(EntryTemplates.EntryCreated != null)
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                        peTemplate.CloneDeep(), pe));
            }
            else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                pd.UINeedsIconUpdate, null, false);
        }
Пример #2
0
        private void OnEntryAdd(object sender, EventArgs e)
        {
            PwGroup pg = GetSelectedGroup();
            Debug.Assert(pg != null); if(pg == null) return;

            if(pg.IsVirtual)
            {
                MessageService.ShowWarning(KPRes.GroupCannotStoreEntries,
                    KPRes.SelectDifferentGroup);
                return;
            }

            PwDatabase pwDb = m_docMgr.ActiveDatabase;
            PwEntry pwe = new PwEntry(true, true);
            pwe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                pwDb.MemoryProtection.ProtectUserName,
                pwDb.DefaultUserName));

            ProtectedString psAutoGen = new ProtectedString(
                pwDb.MemoryProtection.ProtectPassword);
            PwGenerator.Generate(psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile,
                null, Program.PwGeneratorPool);
            pwe.Strings.Set(PwDefs.PasswordField, psAutoGen);

            int nExpireDays = Program.Config.Defaults.NewEntryExpiresInDays;
            if(nExpireDays >= 0)
            {
                pwe.Expires = true;
                pwe.ExpiryTime = DateTime.Now.AddDays(nExpireDays);
            }

            if((pg.IconId != PwIcon.Folder) && (pg.IconId != PwIcon.FolderOpen) &&
                (pg.IconId != PwIcon.FolderPackage))
            {
                pwe.IconId = pg.IconId; // Inherit icon from group
            }
            pwe.CustomIconUuid = pg.CustomIconUuid;

            // Temporarily assume that the entry is in pg; required for retrieving
            // the default auto-type sequence
            pwe.ParentGroup = pg;

            PwEntryForm pForm = new PwEntryForm();
            pForm.InitEx(pwe, PwEditMode.AddNewEntry, pwDb, m_ilCurrentIcons,
                false, false);
            if(UIUtil.ShowDialogAndDestroy(pForm) == DialogResult.OK)
            {
                pg.AddEntry(pwe, true);
                UpdateUI(false, null, pwDb.UINeedsIconUpdate, null, true,
                    null, true, m_lvEntries);

                PwObjectList<PwEntry> vSelect = new PwObjectList<PwEntry>();
                vSelect.Add(pwe);
                SelectEntries(vSelect, true, true);

                EnsureVisibleEntry(pwe.Uuid);
            }
            else UpdateUI(false, null, pwDb.UINeedsIconUpdate, null,
                pwDb.UINeedsIconUpdate, null, false);
        }
Пример #3
0
		private void EditSelectedEntry(bool bSwitchToHistoryTab)
		{
			PwEntry pe = GetSelectedEntry(false);
			if(pe == null) return; // Do not assert

			PwDatabase pwDb = m_docMgr.ActiveDatabase;
			PwEntryForm pForm = new PwEntryForm();
			pForm.InitEx(pe, PwEditMode.EditExistingEntry, pwDb, m_ilCurrentIcons,
				false, false);

			pForm.InitSwitchToHistoryTab = bSwitchToHistoryTab;

			if(pForm.ShowDialog() == DialogResult.OK)
			{
				bool bUpdImg = pwDb.UINeedsIconUpdate;
				RefreshEntriesList(); // Update entry
				UpdateUI(false, null, bUpdImg, null, false, null, pForm.HasModifiedEntry);
			}
			else
			{
				bool bUpdImg = pwDb.UINeedsIconUpdate;
				RefreshEntriesList(); // Update last access time
				UpdateUI(false, null, bUpdImg, null, false, null, false);
			}
			UIUtil.DestroyForm(pForm);
		}
Пример #4
0
        void OpenLoginEditorWindow(PwEntry pe, PwDatabase db)
        {
            PwEntryForm ef = new PwEntryForm();
            ef.InitEx(pe, PwEditMode.EditExistingEntry, host.Database, host.MainWindow.ClientIcons, false, false);

            ef.BringToFront();
            ef.ShowInTaskbar = true;

            host.MainWindow.Focus();
            ef.TopMost = true;
            ef.Focus();
            ef.Activate();

            if (ef.ShowDialog() == DialogResult.OK)
                saveDB(db);
        }
Пример #5
0
        private void OnBtnHistoryView(object sender, EventArgs e)
        {
            Debug.Assert(m_vHistory.UCount == m_lvHistory.Items.Count);

            ListView.SelectedIndexCollection lvsi = m_lvHistory.SelectedIndices;
            if(lvsi.Count != 1) { Debug.Assert(false); return; }

            PwEntry pe = m_vHistory.GetAt((uint)lvsi[0]);
            if(pe == null) { Debug.Assert(false); return; }

            PwEntryForm pwf = new PwEntryForm();
            pwf.InitEx(pe, PwEditMode.ViewReadOnlyEntry, m_pwDatabase,
                m_ilIcons, false, false);

            UIUtil.ShowDialogAndDestroy(pwf);
        }
Пример #6
0
        private static void CreateEntry(PwEntry peTemplate)
        {
            if(peTemplate == null) { Debug.Assert(false); return; }

            PwDatabase pd = Program.MainForm.ActiveDatabase;
            if(pd == null) { Debug.Assert(false); return; }
            if(pd.IsOpen == false) { Debug.Assert(false); return; }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null) pgContainer = pd.RootGroup;

            PwEntry pe = peTemplate.CloneDeep();
            pe.SetUuid(new PwUuid(true), true);
            pe.CreationTime = pe.LastModificationTime = pe.LastAccessTime = DateTime.Now;

            if(EntryTemplates.EntryCreating != null)
                EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                    peTemplate.CloneDeep(), pe));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, pd, Program.MainForm.ClientIcons,
                false, true);

            if(UIUtil.ShowDialogAndDestroy(pef) == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true, true);

                if(EntryTemplates.EntryCreated != null)
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                        peTemplate.CloneDeep(), pe));

                // Program.MainForm.UpdateEntryList(null, true);
                // Program.MainForm.UpdateUIState(true);
                Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                    true, null, true);
            }
            else Program.MainForm.UpdateUI(false, null, pd.UINeedsIconUpdate, null,
                pd.UINeedsIconUpdate, null, false);
        }
Пример #7
0
        private static void CreateEntry(EntryTemplate et)
        {
            if(Program.MainForm.ActiveDatabase.IsOpen == false)
            {
                Debug.Assert(false);
                return;
            }

            PwGroup pgContainer = Program.MainForm.GetSelectedGroup();
            if(pgContainer == null)
                pgContainer = Program.MainForm.ActiveDatabase.RootGroup;

            PwEntry pe = new PwEntry(true, true);

            // pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
            //	Program.MainForm.Database.MemoryProtection.ProtectTitle,
            //	et.Name));

            foreach(EntryTemplateItem eti in et.Items)
                pe.Strings.Set(eti.Name, new ProtectedString(eti.Protected, string.Empty));

            PwEntryForm pef = new PwEntryForm();
            pef.InitEx(pe, PwEditMode.AddNewEntry, Program.MainForm.ActiveDatabase,
                Program.MainForm.ClientIcons, true);

            if(pef.ShowDialog() == DialogResult.OK)
            {
                pgContainer.AddEntry(pe, true);

                // Program.MainForm.UpdateEntryList(null, true);
                // Program.MainForm.UpdateUIState(true);
                Program.MainForm.UpdateUI(false, null, false, null, true, null, true);
            }
            else Program.MainForm.UpdateUI(false, null, false, null, false, null, false);
        }
Пример #8
0
        private void miItem_Edit(object sender, EventArgs e)
        {
            ToolStripMenuItem Item = (ToolStripMenuItem)sender;
            PwEntry Entry = (PwEntry)Item.Tag;
            PwEntryForm myForm = new PwEntryForm();
            myForm.InitEx(Entry, PwEditMode.EditExistingEntry, Host.MainWindow.DocumentManager.ActiveDatabase, Host.MainWindow.ClientIcons, false, true);

            if ((myForm.ShowDialog() == DialogResult.OK))
                Host.MainWindow.UpdateUI(false, null, Host.MainWindow.DocumentManager.ActiveDatabase.UINeedsIconUpdate, null, true, null, true);
            Host.MainWindow.RefreshEntriesList();
        }
Пример #9
0
        private void OnEntryEdit(object sender, EventArgs e)
        {
            PwEntry pe = GetSelectedEntry(false);
            if(pe == null) return; // Do not assert

            PwEntryForm pForm = new PwEntryForm();
            pForm.InitEx(pe, PwEditMode.EditExistingEntry, m_docMgr.ActiveDatabase,
                m_ilCurrentIcons, false);

            if(pForm.ShowDialog() == DialogResult.OK)
            {
                RefreshEntriesList(); // Update entry
                UpdateUIState(pForm.HasModifiedEntry);
            }
            else
            {
                RefreshEntriesList(); // Update last access time
                UpdateUIState(false);
            }
        }
Пример #10
0
        private void OnEntryAdd(object sender, EventArgs e)
        {
            PwEntryForm pForm = new PwEntryForm();

            PwGroup pg = GetSelectedGroup();
            Debug.Assert(pg != null); if(pg == null) return;

            if(pg.IsVirtual)
            {
                MessageService.ShowWarning(KPRes.GroupCannotStoreEntries,
                    KPRes.SelectDifferentGroup);
                return;
            }

            PwDatabase pwDb = m_docMgr.ActiveDatabase;
            PwEntry pwe = new PwEntry(true, true);
            pwe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                pwDb.MemoryProtection.ProtectUserName,
                pwDb.DefaultUserName));

            ProtectedString psAutoGen = new ProtectedString(
                pwDb.MemoryProtection.ProtectPassword);
            PwGenerator.Generate(psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile,
                null);
            pwe.Strings.Set(PwDefs.PasswordField, psAutoGen);

            int nExpireDays = Program.Config.Defaults.NewEntryExpiresInDays;
            if(nExpireDays >= 0)
            {
                pwe.Expires = true;
                pwe.ExpiryTime = DateTime.Now.AddDays(nExpireDays);
            }

            if((pg.IconId != PwIcon.Folder) && (pg.IconId != PwIcon.FolderOpen) &&
                (pg.IconId != PwIcon.FolderPackage))
            {
                pwe.IconId = pg.IconId; // Inherit icon from group
            }

            pForm.InitEx(pwe, PwEditMode.AddNewEntry, pwDb, m_ilCurrentIcons, false);
            if(pForm.ShowDialog() == DialogResult.OK)
            {
                pg.AddEntry(pwe, true);
                UpdateUI(false, null, false, null, true, null, true);
                EnsureVisibleEntry(pwe.Uuid);
            }
        }