コード例 #1
0
ファイル: ContentService.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Add select bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddSingleBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            //Add a space before text.
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // add select text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // set cursor after bookmark
            servicePro.ContentService.MoveChars_Count  = 1;
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
コード例 #2
0
ファイル: IntegrationService.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Add internal bookmark item
        /// </summary>
        /// <param name="bm"></param>
        public void AddInternalBookmark(string key)
        {
            try
            {
                ServicesProfile           serviceProfile = Wkl.MainCtrl.ServiceCtrl.GetProfile(key);
                IntegrationServiceProfile integrationPro = serviceProfile.IntegrationService;
                InternalBookmarkItem      ibmItem        = integrationPro.AddInternalBM_IBookmark;
                if (string.IsNullOrWhiteSpace(ibmItem.DomainName))
                {
                    ibmItem.DomainName = Wkl.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.SelectedDomainName;
                }
                switch (ibmItem.Type)
                {
                case XsltType.Foreach:
                case XsltType.If:
                    InternalBookmarkItem start = ibmItem.Clone();
                    InternalBookmarkItem end   = ibmItem.Clone();

                    start.BizName = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, true);
                    start.Key     = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, true);

                    serviceProfile.IbmItem = start;
                    AddInternalBookmarkItem(key);

                    end.BizName            = MarkupUtilities.GenTextXslTag(ibmItem.BizName, ibmItem.Type, false);
                    end.Key                = MarkupUtilities.GenKeyForXslTag(ibmItem.Key, ibmItem.Type, false);
                    serviceProfile.IbmItem = end;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Select:
                    InternalBookmarkItem select = ibmItem.Clone();
                    select.BizName = MarkupUtilities.GenTextXslTag(select.BizName, select.Type, true);
                    select.Key     = ibmItem.IsImage() ? select.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(select.Key, select.Type, true);

                    serviceProfile.IbmItem = select;
                    AddInternalBookmarkItem(key);
                    break;

                case XsltType.Comment:
                    InternalBookmarkItem comment = ibmItem.Clone();
                    comment.BizName = MarkupUtilities.GenTextXslTag(comment.BizName, comment.Type, true);
                    comment.Key     = ibmItem.IsImage() ? comment.Key + ProntoMarkup.KeyImage
                            : MarkupUtilities.GenKeyForXslTag(comment.Key, comment.Type, true);

                    serviceProfile.IbmItem = comment;
                    AddInternalBookmarkItem(key);
                    break;

                default:
                    break;
                }
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_AddIbmItemError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_AddIbmItemError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_AddIbmItemError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
コード例 #3
0
ファイル: ContentService.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Add foreach bookmark
        /// </summary>
        /// <param name="name">Name of bookmark</param>
        /// <param name="value">Value of bookmark</param>
        private void AddDoubleBookmark(InternalBookmarkItem bm)
        {
            //1. Get FontColor of BM
            //2. Generate tag
            //3. Add start tag (text) to document
            //4. Add start tag to BM
            //5. Move cursor to after
            //6. Add end tag (text) to document
            //7. Add end tag to BM
            //8. Move cursor to between two tags
            //9. Set color

            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            WdColor fontColor  = GetFontColor(bm.Type);
            WdColor textColor  = WdColor.wdColorBlack;
            int     textLength = 0;

            if (Globals.ThisAddIn.Application.Selection.Range.Start != Globals.ThisAddIn.Application.Selection.Range.End)
            {
                textLength = Globals.ThisAddIn.Application.Selection.Range.Text.Length;
                textColor  = Globals.ThisAddIn.Application.Selection.Range.Font.Color;
                servicePro.ContentService.MoveChars_Count  = 1;
                servicePro.ContentService.MoveChars_IsLeft = true;
                MoveChars(key);
            }

            //2.Generate tag
            string startTag = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            //Add a space before text
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            //3. add start foreach text
            servicePro.ContentService.AddToSelection_Text       = startTag.Trim();
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //4. add start foreach bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //5. add space
            servicePro.ContentService.MoveChars_Count  = (textLength > 0 ? textLength + 1 : 1);
            servicePro.ContentService.MoveChars_IsLeft = false;
            MoveChars(key);

            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            //6. add end foreach text
            servicePro.ContentService.AddToSelection_Text       = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, false);
            servicePro.ContentService.AddToSelection_IsSelected = true;
            AddTextToCurrentSelection(key);

            //7. add end foreach bookmarl
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, false);
            AddBookmarkInCurrentSelection(key);
            servicePro.ContentService.AddBookmark_BookmarkReturn.Range.Font.Color = fontColor;
            //if (bm.Type == XsltType.If) // todo: ngocbv add highlight color for condition tag
            //    servicePro.ContentService.AddBookmark_BookmarkReturn.Range.HighlightColorIndex = ProntoMarkup.IfColorBackground;

            //8.set cursor before end tag
            servicePro.ContentService.MoveChars_Count  = 2;
            servicePro.ContentService.MoveChars_IsLeft = true;

            MoveChars(key);

            //9. reset color
            Globals.ThisAddIn.Application.Selection.Font.Color = textColor;

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }
コード例 #4
0
ファイル: ContentService.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// add a comment
        /// </summary>
        /// <pparam name="bm"></pparam>
        private void AddCommentBookmark(InternalBookmarkItem bm)
        {
            string          key;
            ServicesProfile servicePro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out key);

            // add a space before comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to Red
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdRed;
            SetFontForCurrentSelection(key);

            // add select text
            string commentText = MarkupUtilities.GenTextXslTag(bm.BizName, bm.Type, true);

            servicePro.ContentService.AddToSelection_Text       = commentText;
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            // add a space after comment
            servicePro.ContentService.AddToSelection_Text       = " ";
            servicePro.ContentService.AddToSelection_IsSelected = false;
            AddTextToCurrentSelection(key);

            // move left a character to back to comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // select comment
            servicePro.ContentService.MoveChars_Count    = commentText.Length;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = true;
            MoveChars(key);

            // add select bookmark
            servicePro.ContentService.AddBookmark_Name = MarkupUtilities.GenKeyForXslTag(bm.Key, bm.Type, true);
            AddBookmarkInCurrentSelection(key);

            // move to end of comment
            servicePro.ContentService.MoveChars_Count    = 1;
            servicePro.ContentService.MoveChars_IsLeft   = false;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // move to comment text position
            servicePro.ContentService.MoveChars_Count    = ProntoMarkup.ValueCommentTextPosition;
            servicePro.ContentService.MoveChars_IsLeft   = true;
            servicePro.ContentService.MoveChars_IsExtend = false;
            MoveChars(key);

            // change font color to normal
            servicePro.ContentService.WdColorIndex = WdColorIndex.wdBlack;
            SetFontForCurrentSelection(key);

            Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(key);
        }