private void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { try { Debug.Assert(this.package == null); if (this.package != null) { this.package.Dispose(); this.PackageClosed(); } string fileName = (sender as OpenFileDialog).FileName; if (fileName == null || fileName.Length == 0) { return; } Debug.WriteLine("Opening " + fileName + "..."); this.package = new OfficeDocument(fileName); this.PackageLoaded(); this.PackageTreeView(); //UndoRedo _commands = new UndoRedo.Control.Commands(rtbCustomUI.Rtf); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text); } }
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); } }