Exemplo n.º 1
0
        /// <summary>
        /// Initialises the plugin.
        /// </summary>
        /// <param name="host">The plugin host.</param>
        /// <returns>True if the plugin started successfully.</returns>
        public override bool Initialize(IPluginHost host)
        {
            // Start the window monitor so that we can modify new password entry windows.
            this.windowMonitor = new WindowMonitor(host);

            // Create the run as context menu item.
            ContextMenuStrip contextMenu = host.MainWindow.EntryContextMenu;

            contextMenu.Items.Add(new ToolStripSeparator());

            RunAsMenuItem runAsMenuItem = new RunAsMenuItem(host.MainWindow);

            runAsMenuItem.AddToContextMenu(host.MainWindow.EntryContextMenu);
            UIUtil.AssignShortcut(runAsMenuItem, Keys.Control | Keys.E);

            // Return true for a successful startup.
            return(true);
        }
Exemplo n.º 2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon           = AppIcons.Default;
            this.DoubleBuffered = true;

            m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this,
                                                                Program.Config.UI.DataEditorRect);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);
            uint            uStartOffset;
            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out uStartOffset);
            string strData;

            try
            {
                strData = (seiGuess.Encoding.GetString(m_pbData, (int)uStartOffset,
                                                       m_pbData.Length - (int)uStartOffset) ?? string.Empty);
                strData = StrUtil.ReplaceNulls(strData);
            }
            catch (Exception) { Debug.Assert(false); strData = string.Empty; }

            ++m_uBlockEvents;

            UIUtil.AssignShortcut(m_menuFileSave, Keys.Control | Keys.S);
            UIUtil.AssignShortcut(m_menuFileExit, Keys.Escape, null, true);

            UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null, m_menuFileSave);
            UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null);
            UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null);
            UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null);
            UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null);
            UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null);
            UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, null);
            UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, null);
            UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, null);
            UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null);
            UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null);
            UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null);
            UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, null);
            UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, null);
            UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, null);

            string strSearchTr = ((WinUtil.IsAtLeastWindowsVista ?
                                   string.Empty : " ") + KPRes.Search);

            UIUtil.SetCueBanner(m_tbFind, strSearchTr);

            UIUtil.EnableAutoCompletion(m_tbFontCombo, true);
            UIUtil.EnableAutoCompletion(m_tbFontSizeCombo, true);

            m_rtbText.Dock = DockStyle.Fill;
            m_ctxText.Attach(m_rtbText, this);
            m_tssStatusMain.Text = KPRes.Ready;
            m_rtbText.WordWrap   = Program.Config.UI.DataEditorWordWrap;

            InitFormattingToolBar();

            bool bSimpleText = true, bDefaultFont = true;

            if (m_bdc == BinaryDataClass.RichText)
            {
                try
                {
                    if (strData.Length > 0)
                    {
                        m_rtbText.Rtf = StrUtil.RtfFix(strData);
                        bDefaultFont  = false;
                    }
                    else
                    {
                        m_rtbText.Text = string.Empty;
                    }

                    bSimpleText = false;
                }
                catch (Exception) { }                // Show as simple text
            }

            if (bSimpleText)
            {
                m_rtbText.Text           = strData;
                m_rtbText.SimpleTextOnly = true;

                // CR is upgraded to CR+LF
                m_bNewLinesWin = (StrUtil.GetNewLineSeq(strData) != "\n");
            }
            else
            {
                m_menuViewFont.Text = KPRes.FontDefault + "...";
            }

            if (bDefaultFont && Program.Config.UI.DataEditorFont.OverrideUIDefault)
            {
                m_rtbText.SelectAll();
                m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont();
            }

            m_rtbText.Select(0, 0);
            --m_uBlockEvents;
            UpdateUIState(false, true);
        }
Exemplo n.º 3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon           = Properties.Resources.KeePass;
            this.DoubleBuffered = true;

            string strRect = Program.Config.UI.DataEditorRect;

            if (strRect.Length > 0)
            {
                UIUtil.SetWindowScreenRect(this, strRect);
            }
            m_strInitialFormRect = UIUtil.GetWindowScreenRect(this);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);
            uint            uStartOffset;
            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out uStartOffset);
            string strData;

            try
            {
                strData = (seiGuess.Encoding.GetString(m_pbData, (int)uStartOffset,
                                                       m_pbData.Length - (int)uStartOffset) ?? string.Empty);
            }
            catch (Exception) { Debug.Assert(false); strData = string.Empty; }

            BlockUIEvents(true);

            UIUtil.AssignShortcut(m_menuFileSave, Keys.Control | Keys.S);
            m_menuFileExit.ShortcutKeyDisplayString = KPRes.KeyboardKeyEsc;

            UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null, m_menuFileSave);
            UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null);
            UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null);
            UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null);
            UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null);
            UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null);
            UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, null);
            UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, null);
            UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, null);
            UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null);
            UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null);
            UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null);
            UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, null);
            UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, null);
            UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, null);

            UIUtil.EnableAutoCompletion(m_tbFontCombo, true);
            UIUtil.EnableAutoCompletion(m_tbFontSizeCombo, true);

            m_rtbText.Dock = DockStyle.Fill;
            m_ctxText.Attach(m_rtbText, this);
            m_tssStatusMain.Text = KPRes.Ready;
            m_rtbText.WordWrap   = Program.Config.UI.DataEditorWordWrap;

            InitFormattingToolBar();

            bool bSimpleText = true;

            if (m_bdc == BinaryDataClass.RichText)
            {
                try
                {
                    if (strData.Length > 0)
                    {
                        m_rtbText.Rtf = strData;
                    }
                    else
                    {
                        m_rtbText.Text = string.Empty;
                    }

                    bSimpleText = false;
                }
                catch (Exception) { }                // Show as simple text
            }

            if (bSimpleText)
            {
                m_rtbText.Text           = strData;
                m_rtbText.SimpleTextOnly = true;

                if (Program.Config.UI.DataEditorFont.OverrideUIDefault)
                {
                    m_rtbText.SelectAll();
                    m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont();
                }
            }

            m_rtbText.Select(0, 0);
            BlockUIEvents(false);
            UpdateUIState(false, true);
        }