public EditContentForm(AnchorData settings, string[] anchorNames)
            : this()
        {
            _anchorNames = anchorNames;
            _currentAnchorSettings = settings;
            this.ConfigureForm(_currentAnchorSettings);

            this.btnOK.Enabled = false;
        }
 public pnlAnchorEditor(AnchorData settings)
     : base(settings)
 {
     InitializeComponent();
     this.chkShowAnchorText.CheckedChanged += new EventHandler(chkShowAnchorText_CheckedChanged);
     this.txtAnchorName.TextChanged += new EventHandler(txtAnchorName_TextChanged);
     this.txtDisplayText.TextChanged += new EventHandler(txtDisplayText_TextChanged);
     this.Load += new EventHandler(pnlAnchorEditor_Load);
 }
        public pnlLinkEditor(string[] anchorNames, AnchorData settings)
            : base(settings)
        {
            InitializeComponent();

            _anchorNames = anchorNames;

            this.txtDisplayText.TextChanged += new EventHandler(txtDisplayText_TextChanged);
            this.lvSelectedAnchor.ItemSelectionChanged +=new ListViewItemSelectionChangedEventHandler(lvSelectedAnchor_ItemSelect);
            this.lvSelectedAnchor.MouseDown +=new MouseEventHandler(lvSelectedAnchor_MouseDown);
            this.lvSelectedAnchor.MouseDoubleClick +=new MouseEventHandler(lvSelectedAnchor_MouseDoubleClick);
            this.Load += new EventHandler(pnlLinkEditor_Load);
            this.txtAnchorName.Enabled = false;
        }
        private void ConfigureForm(AnchorData settings)
        {
            if (settings.AnchorClass == AnchorClass.wlwStaticAnchor)
            {
                this.FormSetupEditAnchorConfig();
            }

            if (settings.AnchorClass == AnchorClass.wlwStaticLink)
            {
                this.FormSetupEditLinkConfig();
            }
        }
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
        {
            AnchorData anchorData = new AnchorData();
            IHTMLElement selectedElement;
            IHTMLElement selectedAnchor;

            // This is passed by ref, and messes with our ability to
            // manipulate the editor contents. Zero it out until we're done:
            content = "";

            WLWEditorContent currentEditor = new WLWEditorContent(dialogOwner.Handle);

            _namedAnchorDictionary = currentEditor.getStaticAnchorsDictionary();
            _namedLinkDictionary = currentEditor.getStaticLinksDictionary();

            // Remember what was selected, in case the user cancels the operation:
            string _selectedText = "";
            string _selectedHtml = "";

            try
            {
                selectedElement = currentEditor.getSelectedElement();

                // Subsequent operations in this scope modify these values in the editor,
                // and we need to be able to reset them on cancel:
                _selectedText = selectedElement.innerText;
                _selectedHtml = selectedElement.outerHTML;

                // Processes within THIS call may modify contents of selectedElement.
                // This call must FOLLOW CAPTURE of innerText and outerHtml as above:
                selectedAnchor = currentEditor.getSelectedAnchor(selectedElement);

                anchorData.AnchorClass = AnchorClassSelector.selectByName(selectedAnchor.className);
                anchorData.AnchorID = selectedAnchor.id;
                anchorData.DisplayText = selectedAnchor.innerText;

                /*
                 * The ID of the anchor that is the target of a static link can be parsed
                 * from the link ID (composed of anchorID + Link Class Name and possibly
                 * an integer if more than one link to same anchor)
                 */
                anchorData.TargetAnchorID = this.getAnchorIDFromLinkID(anchorData.AnchorID);
            }
            catch (Exception)
            {
                MessageBox.Show("You cannot attach an anchor to this type of object");
                return DialogResult.Cancel;
            }

            // get string array of anchor names to pass to the Link Editor Form:
            string[] anchorNamesArray = new string[_namedAnchorDictionary.Count];
            _namedAnchorDictionary.Keys.CopyTo(anchorNamesArray, 0);

            using (var editContentForm = new EditContentForm(anchorData, anchorNamesArray))
            {
                if (editContentForm.ShowDialog() == DialogResult.OK)
                {
                    switch (anchorData.AnchorClass)
                    {
                        case AnchorClass.wlwStaticAnchor:

                            anchorData.AnchorID = this.getUniqueAnchorId(anchorData.AnchorID, selectedAnchor.id);
                            /*
                             * Capture the original and new AnchorID/href for updating links which refer to
                             * the current anchor (in case the AnchorID has been Modified):
                             */
                            string oldAnchorID = selectedAnchor.id;
                            string oldHref= "#" + oldAnchorID;
                            string newHref = anchorData.LinkHref;

                            // Set the new values . . .
                            selectedAnchor.id = anchorData.AnchorID;
                            selectedAnchor.innerText = anchorData.DisplayText;
                            selectedAnchor.className = anchorData.AnchorClass.ToString();

                            if (oldAnchorID != selectedAnchor.id)
                            {
                                // Update any links that refer to the old anchor id:
                                this.updateLinkReferences(oldHref, newHref);
                            }
                            break;

                        case AnchorClass.wlwStaticLink:
                            selectedAnchor.id = this.getUniqueLinkId(anchorData, selectedAnchor.id);
                            selectedAnchor.className = anchorData.AnchorClass.ToString();
                            selectedAnchor.innerText = anchorData.DisplayText;
                            IHTMLAnchorElement anchor = (IHTMLAnchorElement)selectedAnchor;
                            anchor.href = anchorData.LinkHref;
                            break;
                    }
                }
                else
                {
                    // Reset the contents of the originally selected element:
                    selectedElement.outerHTML = _selectedHtml;
                    return DialogResult.Cancel;
                }
            }

            // Make sure that the text contained within the anchor is selected in the editor:
            currentEditor.MoveSelectionToElementText(selectedAnchor);

            if (selectedAnchor.innerText != null)
            {
                /*
                 * ref variable content will replace whatever the current selection in the editor
                 * contains. Make sure the text that is replaced represents the inner text
                 * of the Anchor Element, or weird shit happens.
                 */
                content = selectedAnchor.innerText;
            }

            /*
             * These need to be nulled out, because they are not
             * re-initialized with successive uses of the plugin:
             */
            _namedAnchorDictionary = null;
            _namedLinkDictionary = null;

            return DialogResult.OK;
        }
        private string getUniqueLinkId(AnchorData NewAnchorData, string currentLinkId)
        {
            // Link Id's are a concatenation of the target anchorID and the Link Class:
            string proposedID = NewAnchorData.AnchorID + ":" + NewAnchorData.AnchorClass.ToString();
            string output = proposedID;

            // Uniqueness is created by incrementing integer:
            int uniqueNameIndex = this.getUniqueLinkNameIndex(output);
            if (uniqueNameIndex > 0 && proposedID != currentLinkId)
            {
                output = proposedID + "_" + uniqueNameIndex;
            }

            return output;
        }
 public pnlAnchorEditorBase(AnchorData settings)
     : this()
 {
     InitializeComponent();
     this.AnchorSettings = settings;
 }