예제 #1
0
 /// <summary>
 /// Finds the next redaction mark in the document.
 /// </summary>
 /// <param name="CurrentRange">The range containing the starting point of the search. Changes to the location of the output mark if one is found.</param>
 /// <param name="CurrentView">The current view type.</param>
 /// <param name="WrapAtEnd">True to prompt to wrap around at the end, otherwise False.</param>
 /// <returns>True if a mark was found, otherwise False.</returns>
 private bool FindNextMark(ref Word.Range CurrentRange, Word.WdViewType CurrentView, bool WrapAtEnd)
 {
     if (FindNextMarkInCurrentStory(ref CurrentRange) || FindNextMarkInOtherStory(ref CurrentRange))
     {
         //extend it out and select it
         ExtendNextMark(ref CurrentRange, false);
         CurrentRange.Select();
         return(true);
     }
     else
     {
         if (WrapAtEnd)
         {
             if (GenericMessageBox.Show(Resources.SearchFromBeginning, Resources.AppName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0) == DialogResult.OK)
             {
                 //move the range to the start of the document and search again
                 CurrentRange = CurrentRange.Document.StoryRanges[Word.WdStoryType.wdMainTextStory];
                 CurrentRange.Collapse(ref CollapseStart);
                 return(FindNextMark(ref CurrentRange, CurrentView, false));
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             GenericMessageBox.Show(Resources.NoRedactionMarks, Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
             return(false);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Finds the previous redaction mark in the document.
        /// </summary>
        /// <param name="CurrentRange">The range containing the starting point of the search. Changes to the location of the output mark if one is found.</param>
        /// <param name="CurrentView">The current view type.</param>
        /// <param name="WrapAtStart">True to prompt to wrap around at the start, otherwise False.</param>
        /// <returns>True if a mark was found, otherwise False.</returns>
        private bool FindPreviousMark(ref Word.Range CurrentRange, Word.WdViewType CurrentView, bool WrapAtStart)
        {
            if (FindPreviousMarkInCurrentStory(ref CurrentRange) || FindPreviousMarkInOtherStory(ref CurrentRange))
            {
                //extend it out and select it
                ExtendPreviousMark(ref CurrentRange, false);
                CurrentRange.Select();
                return(true);
            }
            else
            {
                if (WrapAtStart)
                {
                    if (GenericMessageBox.Show(Resources.SearchFromEnd, Resources.AppName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0) == DialogResult.OK)
                    {
                        //they want to wrap around, so find the last story and start again
                        CurrentRange = GetLastStory(ref CurrentRange);
                        CurrentRange.Collapse(ref CollapseEnd);

                        return(FindPreviousMark(ref CurrentRange, CurrentView, false));
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    GenericMessageBox.Show(Resources.NoRedactionMarks, Resources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                    return(false);
                }
            }
        }
예제 #3
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();
        }
예제 #4
0
        /// <summary>
        /// Unmark the entire document.
        /// </summary>
        private void UnmarkDocument()
        {
            Application.ScreenUpdating = false;

            Word.Range      OriginalSelection = Application.Selection.Range.Duplicate;
            Word.WdViewType OriginalView      = Application.ActiveWindow.View.Type;

            foreach (Word.Range StoryRange in Application.Selection.Document.StoryRanges)
            {
                UnmarkRange(StoryRange, true);
            }

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

            Application.ScreenUpdating = true;
        }
예제 #5
0
        /// <summary>
        /// Selects the next mark (relative to the current selection).
        /// </summary>
        private void SelectNextMark()
        {
            Application.ScreenUpdating = false;
            Word.WdViewType OriginalView = Application.ActiveWindow.View.Type;

            Word.Selection CurrentSelection  = Application.Selection;
            Word.Range     OriginalSelection = CurrentSelection.Range.Duplicate;

            //collapse to the end of the current selection
            Word.Range SelectionRange = CurrentSelection.Range;
            SelectionRange.Collapse(ref CollapseEnd);
            ExtendNextMark(ref SelectionRange, true);

            if (!FindNextMark(ref SelectionRange, OriginalView, (CurrentSelection.StoryType != Word.WdStoryType.wdMainTextStory || CurrentSelection.End != 0) /* don't wrap from cp0 */))
            {
                OriginalSelection.Select();
            }

            Application.ScreenUpdating = true;
        }
예제 #6
0
        /// <summary>
        /// Selects the previous mark (relative to the current selection).
        /// </summary>
        private void SelectPreviousMark()
        {
            Application.ScreenUpdating = false;
            Word.WdViewType OriginalView = Application.ActiveWindow.View.Type;

            Word.Selection CurrentSelection  = Application.Selection;
            Word.Range     OriginalSelection = CurrentSelection.Range.Duplicate;

            //collapse to the start of the current selection
            Word.Range SelectionRange = CurrentSelection.Range;
            SelectionRange.Collapse(ref CollapseStart);
            ExtendPreviousMark(ref SelectionRange, true);

            if (!FindPreviousMark(ref SelectionRange, OriginalView, (SelectionRange.StoryType != Word.WdStoryType.wdEndnoteSeparatorStory || SelectionRange.End < SelectionRange.Document.StoryRanges[Word.WdStoryType.wdEndnoteSeparatorStory].StoryLength - 1)))
            {
                OriginalSelection.Select();
            }

            Application.ScreenUpdating = true;
        }
예제 #7
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();
        }
예제 #8
0
 /// <summary>
 /// 设置视图
 /// </summary>
 /// <param name="ViewType"></param>
 public void SetView(Word.WdViewType ViewType) {
     this._wordApplication.ActiveWindow.View.Type = ViewType;
 }