Exemplo n.º 1
0
        private void sampleMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem sample         = sender as ToolStripMenuItem;
            string            sampleFileName = sample.Tag as string;

            Debug.Assert(sampleFileName.Length > 0);
            if (this.rtbCustomUI.Text != null && this.rtbCustomUI.Text.Length > 0)
            {
                if (!this.OKToTrash())
                {
                    return;
                }
            }

            if (this.package != null && !this.package.HasCustomUI)
            {
                addPart(XMLParts.RibbonX14);
                this.rtbCustomUI.Tag = XMLParts.RibbonX14;
                this.office14PartToolStripMenuItem.Enabled = false;
            }

            try
            {
                this.colorTimer.Stop();
                TextReader tr = new StreamReader(sampleFileName);
                this.rtbCustomUI.Rtf = XmlColorizer.Colorize(tr.ReadToEnd());

                if (this.package != null)
                {
                    rtfContents[(int)((XMLParts)this.rtbCustomUI.Tag)] = this.rtbCustomUI.Rtf;
                }
                else
                {
                    rtbCustomUI.Tag = XMLParts.RibbonX14;
                }

                tr.Close();

                //UndoRedo
                if (_commands != null)
                {
                    _commands.NewCommand("Paste", rtbCustomUI.Rtf, rtbCustomUI.Text, rtbCustomUI.SelectionStart);
                }
                else
                {
                    _commands = new UndoRedo.Control.Commands(rtbCustomUI.Rtf);
                }
            }
            catch (System.Exception ex)
            {
                Debug.Assert(false, ex.Message);
                Debug.Fail(ex.Message);
            }
        }
        private void PackageLoaded()
        {
            this.SuspendLayout();

            this.rtbCustomUI.ReadOnly = this.package.ReadOnly;

            string readOnly = (this.rtbCustomUI.ReadOnly ? " (" + StringsResource.idsReadOnly + ")" : String.Empty);

            this.Text = Path.GetFileName(this.package.Name) + readOnly + " - " + this.Text;
            this.lbDocumentName.Text = this.package.Name + readOnly;

            if (this.package.Parts != null && this.package.Parts.Count > 0)
            {
                if (this.rtbCustomUI.Tag != null)
                {
                    this.rtbCustomUI.Rtf = string.Empty;
                    rtfContents[(int)this.rtbCustomUI.Tag] = string.Empty;
                }

                foreach (OfficePart part in this.package.Parts)
                {
                    int contentIndex = (int)part.PartType;
                    rtbCustomUI.Rtf           = XmlColorizer.Colorize(part.ReadContent());
                    rtbCustomUI.Tag           = part.PartType;
                    rtfContents[contentIndex] = rtbCustomUI.Rtf;
                }
            }
            else
            {
                this.rtbCustomUI.Tag = XMLParts.RibbonX14;
            }

            this.sampleToolStripMenuItem.Enabled = !this.package.ReadOnly;

            this.ChangePackageButtonState(true);

            this.splMainContainer.Panel1Collapsed = false;

            this.rtbCustomUI.Modified = false;

            this.ResumeLayout();
        }
        private void colorTimer_Tick(object sender, EventArgs e)
        {
            this.colorTimer.Stop();

            int  selectionStart  = this.rtbCustomUI.SelectionStart;
            int  selectionLength = this.rtbCustomUI.SelectionLength;
            bool modified        = this.rtbCustomUI.Modified;

            System.Drawing.Point pVisiblePoint = this.rtbCustomUI.GetPositionFromCharIndex(selectionStart);

            this.rtbCustomUI.SuspendLayout();
            this.rtbCustomUI.Rtf = XmlColorizer.Colorize(this.rtbCustomUI.Text);

            this.rtbCustomUI.SelectionStart  = selectionStart;
            this.rtbCustomUI.SelectionLength = selectionLength;
            this.rtbCustomUI.Modified        = modified;

            this.rtbCustomUI.ResumeLayout();

            this.colorTimer.Stop();
        }