Beispiel #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();

            pe.History.Clear();

            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);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private static void OnMenuExecute(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = (sender as ToolStripMenuItem);

            if (tsmi == null)
            {
                Debug.Assert(false); return;
            }

            PwEntry peTemplate = (tsmi.Tag as PwEntry);

            if (peTemplate == null)
            {
                Debug.Assert(false); return;
            }

            MainForm mf = Program.MainForm;

            if (mf == null)
            {
                Debug.Assert(false); return;
            }

            PwDatabase pd = mf.ActiveDatabase;

            if ((pd == null) || !pd.IsOpen)
            {
                Debug.Assert(false); return;
            }

            // Ensure that the correct database is still active
            if (pd != mf.DocumentManager.FindContainerOf(peTemplate))
            {
                return;
            }

            GFunc <PwEntry> fNewEntry = delegate()
            {
                PwEntry pe = peTemplate.Duplicate();
                pe.History.Clear();
                return(pe);
            };

            Action <PwEntry> fAddPre = delegate(PwEntry pe)
            {
                if (EntryTemplates.EntryCreating != null)
                {
                    EntryTemplates.EntryCreating(null, new TemplateEntryEventArgs(
                                                     peTemplate.CloneDeep(), pe));
                }
            };

            Action <PwEntry> fAddPost = delegate(PwEntry pe)
            {
                if (EntryTemplates.EntryCreated != null)
                {
                    EntryTemplates.EntryCreated(null, new TemplateEntryEventArgs(
                                                    peTemplate.CloneDeep(), pe));
                }
            };

            mf.AddEntryEx(null, fNewEntry, fAddPre, fAddPost);
        }