Beispiel #1
0
        /// <summary>
        /// Redact the current document.
        /// </summary>
        private void RedactDocument()
        {
            object Story = Word.WdUnits.wdStory;

            Word.WdViewType OriginalView = Application.ActiveWindow.View.Type;
            Application.ScreenUpdating = false;

            Word.Document SourceFile = Application.ActiveDocument;

            //cache the document's saved and update styles from template states
            bool Saved        = SourceFile.Saved;
            bool UpdateStyles = SourceFile.UpdateStylesOnOpen;

            //BUG 5819: need to make sure this is off so that Normal's properties don't get demoted into redacted file
            Application.ActiveDocument.UpdateStylesOnOpen = false;
            Word.Document FileToRedact = RedactCommon.CloneDocument(Application.ActiveDocument);

            //reset those states to their cached values
            SourceFile.UpdateStylesOnOpen = UpdateStyles;
            SourceFile.Saved = Saved;

            //get the window for the document surface (_WwG)
            NativeWindow WordWindow = RedactCommon.GetDocumentSurfaceWindow();

            //show progress UI
            using (FormDoRedaction ProgressUI = new FormDoRedaction(FileToRedact, this))
            {
                ProgressUI.ResetProgress();
                DialogResult RedactResult = ProgressUI.ShowDialog();

                //fix the view
                Application.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
                Application.ActiveWindow.View.Type     = OriginalView;
                Application.Selection.HomeKey(ref Story, ref Missing);

                if (RedactResult != DialogResult.OK)
                {
                    GenericMessageBox.Show(Resources.RedactionFailed, Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                }
                else
                {
                    //dialog telling the user we're done
                    using (FormSuccess Success = new FormSuccess(FileToRedact.Application))
                        Success.ShowDialog(WordWindow);
                }
            }

            //set focus back onto the document
            NativeMethods.SetFocus(WordWindow.Handle);

            //we need to release our handle, or Word will crash on close as the CLR tries to do it for us
            WordWindow.ReleaseHandle();
        }
Beispiel #2
0
        /// <summary>
        /// Show the Find and Mark dialog box.
        /// </summary>
        private void FindAndMark()
        {
            Word.Range      OriginalSelection = Application.Selection.Range.Duplicate;
            Word.WdViewType OriginalView      = Application.ActiveWindow.View.Type;

            //get the window for the document surface (_WwG)
            NativeWindow WordWindow = RedactCommon.GetDocumentSurfaceWindow();

            using (FormFindAndMark find = new FormFindAndMark(ShadingColor))
            {
                find.ShowDialog(WordWindow);
            }

            //set focus back onto the document
            NativeMethods.SetFocus(WordWindow.Handle);

            //we need to release our handle, or Word will crash on close as the CLR tries to do it for us
            WordWindow.ReleaseHandle();

            Application.ActiveWindow.View.Type = OriginalView;
            OriginalSelection.Select();
        }