示例#1
0
        public override void Terminate()
        {
            if (mHost == null)
            {
                return;
            }

            mOriginalEntryView.FontChanged  -= mOriginalEntryView_FontChanged;
            mHost.MainWindow.UIStateUpdated -= this.OnUIStateUpdated;

            // Restore original entry view to it's normal place
            mEntryView.Parent.Controls.Add(mOriginalEntryView);
            mEntryView.Parent.Controls.Remove(mEntryView);
            mOriginalEntryView = null;

            if (mEntriesListView != null)
            {
                mEntriesListView.Invalidated -= mEntitiesListView_Invalidated;
                mEntriesListView              = null;
            }

            mEntryView.Dispose();
            mEntryView = null;

            mHost.MainWindow.ToolsMenu.DropDownItems.Remove(mOptions.Menu);

            mHost = null;
        }
示例#2
0
        public override bool Initialize(IPluginHost host)
        {
            if (host == null)
            {
                return(false);
            }

            // Ensure terminate before initialise, in unlikely case of double initialisation
            Terminate();

            mHost = host;

            // Add an Options menu
            mOptions = new Options(mHost);
            mHost.MainWindow.ToolsMenu.DropDownItems.Add(mOptions.Menu);

            mOptions.OptionChanged += mOptions_OptionChanged;

            mOriginalEntryView = FindControl <RichTextBox>("m_richEntryView");
            var entryViewContainer = mOriginalEntryView.Parent;

            if (mOriginalEntryView == null || entryViewContainer == null)
            {
                Debug.Fail("Couldn't find existing entry view to replace");
                mHost = null;
                return(false);
            }

            // Replace existing entry view with new one
            mEntryView = new EntryView(mHost.MainWindow, mOptions)
            {
                Name         = "m_KPEnhancedEntryView",
                Dock         = DockStyle.Fill,
                AutoValidate = AutoValidate.Disable                 // Don't allow our internal validation to bubble upwards to KeePass
            };

            entryViewContainer.Controls.Add(mEntryView);

            // Move the original entry view into a tab on the new view
            entryViewContainer.Controls.Remove(mOriginalEntryView);
            mEntryView.AllTextControl = mOriginalEntryView;

            // Font is assigned, not inherited. So assign here too, and follow any changes
            mOriginalEntryView.FontChanged += mOriginalEntryView_FontChanged;
            mOriginalEntryView_FontChanged(null, EventArgs.Empty);

            // Hook UIStateUpdated to watch for current entry changing.
            mHost.MainWindow.UIStateUpdated += this.OnUIStateUpdated;

            // Database may be saved while in the middle of editing Notes. Watch for that and commit the current edit if that happens
            mHost.MainWindow.FileSaving += this.OnFileSaving;

            if (PwDefs.FileVersion64 < StrUtil.ParseVersion("2.22"))             // Fixed in KeePass 2.22
            {
                // HACK: UIStateUpdated isn't called when navigating a reference link in the entry view, so grab that too.
                mOriginalEntryView.LinkClicked += this.OnUIStateUpdated;
            }

            // HACK: UIStateUpdated isn't called when toggling column value hiding on and off, so monitor the entries list for being invalidated
            mEntriesListView = FindControl <Control>("m_lvEntries");
            if (mEntriesListView != null)
            {
                mEntriesListView.Invalidated += mEntitiesListView_Invalidated;
            }

            // Hook events to update the UI when the entry is modified
            mEntryView.EntryModified += this.mEntryView_EntryModified;

            return(true);
        }