コード例 #1
0
ファイル: SearchWindow.cs プロジェクト: amnore/AutoTypeSearch
        private void EditEntry(SearchResult searchResult)
        {
            using (var entryForm = new PwEntryForm())
            {
                mMainForm.MakeDocumentActive(mMainForm.DocumentManager.FindDocument(searchResult.Database));

                entryForm.InitEx(searchResult.Entry, PwEditMode.EditExistingEntry, searchResult.Database, mMainForm.ClientIcons, false, false);

                ShowForegroundDialog(entryForm);

                mMainForm.UpdateUI(false, null, searchResult.Database.UINeedsIconUpdate, null, true, null, entryForm.HasModifiedEntry);
            }
        }
コード例 #2
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();
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        private void lvExpiringPasswordsItem_onDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo lvHit = lvExpiringPasswords.HitTest(e.Location);
            ListViewItem        lvi   = lvHit.Item;
            PwListItem          pli   = (lvi.Tag as PwListItem);
            PwEntry             pe    = pli.Entry;

            if (pe == null || pdb == null || il_icons == null)
            {
                return;                                                // Do not assert
            }
            pe.CreationTime         = DateTime.Parse("20.12.2019");
            pe.LastModificationTime = DateTime.Parse("20.12.2019");
            this.Close();

            PwDatabase  pwDb  = pdb;
            PwEntryForm pForm = new PwEntryForm();

            pForm.InitEx(pe, PwEditMode.EditExistingEntry, pwDb, il_icons,
                         false, false);

            DialogResult dr   = pForm.ShowDialog();
            bool         bMod = ((dr == DialogResult.OK) && pForm.HasModifiedEntry);

            UIUtil.DestroyForm(pForm);

            bool bUpdImg = pwDb.UINeedsIconUpdate;
            PwObjectList <PwEntry> pwEntries = new PwObjectList <PwEntry>();

            pwEntries.Add(pe);
            MainForm mf = Program.MainForm;

            mf.SelectEntries(pwEntries, true, true);
            mf.RefreshEntriesList();
            mf.UpdateUI(false, null, bUpdImg, null, false, null, bMod);

            if (Program.Config.Application.AutoSaveAfterEntryEdit && bMod)
            {
                mf.SaveDatabase(pwDb, null);
            }
        }
コード例 #5
0
        private void CreateEntry()
        {
            if (mCreatingEntry)
            {
                return;
            }
            mCreatingEntry = true;
            try
            {
                // Unlock, if required
                m_host.MainWindow.ProcessAppMessage((IntPtr)Program.AppMessage.Unlock, IntPtr.Zero);

                if (m_host.MainWindow.IsAtLeastOneFileOpen())
                {
                    string selectedText, url, title;
                    WebBrowserUrl.GetFocusedBrowserInfo(mChromeAccessibility, out selectedText, out url, out title);

                    var urlSuggestions = new List <String>();
                    if (!String.IsNullOrEmpty(url))
                    {
                        // Use only the root part of the URL
                        try
                        {
                            var uri = new Uri(url);
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Authority) + "/");
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Path));
                            urlSuggestions.Add(uri.GetLeftPart(UriPartial.Query));
                        }
                        catch (UriFormatException)
                        {
                        }
                        // Finally, the url exactly as given
                        urlSuggestions.Add(url);
                    }

                    // Logic adapted from EntryTemplates.CreateEntry
                    var database = m_host.Database;
                    var entry    = new PwEntry(true, true);
                    if (!String.IsNullOrEmpty(title))
                    {
                        entry.Strings.Set(PwDefs.TitleField, new ProtectedString(database.MemoryProtection.ProtectTitle, title));
                    }
                    if (urlSuggestions.Any())
                    {
                        entry.Strings.Set(PwDefs.UrlField, new ProtectedString(database.MemoryProtection.ProtectUrl, urlSuggestions[0]));
                    }
                    if (!String.IsNullOrEmpty(selectedText))
                    {
                        entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(database.MemoryProtection.ProtectUserName, selectedText));
                    }

                    // Generate a default password, the same as in MainForm.OnEntryAdd
                    ProtectedString psAutoGen;
                    PwGenerator.Generate(out psAutoGen, Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile, null, Program.PwGeneratorPool);
                    psAutoGen = psAutoGen.WithProtection(database.MemoryProtection.ProtectPassword);
                    entry.Strings.Set(PwDefs.PasswordField, psAutoGen);


                    PwGroup group = database.RootGroup;
                    if (CreateEntryTargetGroup != null)
                    {
                        group = database.RootGroup.FindGroup(CreateEntryTargetGroup, true) ?? database.RootGroup;
                    }

                    // Set parent group temporarily, so that the AutoType tab, and other plugins such as PEDCalc, can obtain it in the PwEntryForm.
                    //entry.ParentGroup = group;
                    var parentGroupProperty = typeof(PwEntry).GetProperty("ParentGroup", BindingFlags.Instance | BindingFlags.Public);
                    if (parentGroupProperty != null)
                    {
                        parentGroupProperty.SetValue(entry, @group);
                    }

                    using (var entryForm = new PwEntryForm())
                    {
                        entryForm.InitEx(entry, PwEditMode.AddNewEntry, database, m_host.MainWindow.ClientIcons, false, true);

                        // Customise entry form to show drop-down for selecting URL
                        var urlBox = entryForm.Controls.Find("m_tbUrl", true).FirstOrDefault();
                        if (urlBox != null)
                        {
                            var urlCombo = new ComboBox
                            {
                                DropDownStyle = ComboBoxStyle.DropDown,
                                TabIndex      = urlBox.TabIndex,
                                Text          = urlBox.Text,
                            };
                            foreach (var urlSuggestion in urlSuggestions.Distinct())
                            {
                                urlCombo.Items.Add(urlSuggestion);
                            }
                            var syncPos = new EventHandler(delegate { urlCombo.SetBounds(urlBox.Left, urlBox.Top, urlBox.Width, urlBox.Height); });
                            urlBox.Resize += syncPos;
                            syncPos(null, EventArgs.Empty);                             // Initial sizing
                            urlBox.Parent.Controls.Add(urlCombo);
                            urlBox.Visible = false;

                            // Sync text
                            urlCombo.TextChanged += delegate { urlBox.Text = urlCombo.Text; };
                            urlBox.TextChanged   += delegate { urlCombo.Text = urlBox.Text; };
                        }

                        if (ShowForegroundDialog(entryForm) == DialogResult.OK)
                        {
                            group.AddEntry(entry, true, true);
                            m_host.MainWindow.UpdateUI(false, null, database.UINeedsIconUpdate, null, true, null, true);
                        }
                        else
                        {
                            m_host.MainWindow.UpdateUI(false, null, database.UINeedsIconUpdate, null, database.UINeedsIconUpdate, null, false);
                        }
                    }
                }
            }
            finally
            {
                mCreatingEntry = false;
            }
        }
コード例 #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.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);
            }
        }
コード例 #7
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.Uuid         = new PwUuid(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 (pef.ShowDialog() == 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);
            }
        }