Exemplo n.º 1
0
 private void moduleProperties_Click(object sender, EventArgs e)
 {
     HtmlAgilityPack.HtmlDocument doc  = HTMLDocumentConverter.mshtmlDocToAgilityPackDoc(htmlEditor1.HtmlDocument2);
     HtmlAgilityPack.HtmlNode     elem = doc.GetElementbyId(this.activeElement.id);
     CFormController.Instance.mainForm.propertiesForm.moduleChanged += new ModuleChanged(propertiesForm_moduleChanged);
     CFormController.Instance.mainForm.showProperties(elem);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method needs heavy revision.
        ///
        /// Since element on which was module dropped is COM interface IHTMLElement
        /// and that seems like it's not supporting own module tag (it gets removed on whatever operation),
        /// this method adds id to IHTMLElement(if needed), to be able to identify it in HtmlAgilityPack HtmlDocument
        /// then adds preview output as end to that element, then converts document back to COM IHTMLDocument2
        ///
        /// Doh.
        ///
        /// TODO: Could use hard refactoring, probably own customized html editor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void theSite_drop(DataObject sender, DragEventArgs e)
        {
            CFormController.Instance.mainForm.setStatus("Module(s) Added");
            if (sender.GetData("System.Windows.Forms.ListView+SelectedListViewItemCollection", false) != null)
            {
                // Get module preview (multiple modules can be dragged)
                String input = String.Empty;
                ListView.SelectedListViewItemCollection listViewItemModules = (ListView.SelectedListViewItemCollection)sender.GetData("System.Windows.Forms.ListView+SelectedListViewItemCollection", false);
                foreach (ListViewItem listViewItemModule in listViewItemModules)
                {
                    input += CXMLParser.Instance.GetPreviewFromProjectXML(CXMLParser.Instance.GetNodeFromModule(CModuleReader.Instance.GetModuleInstanceFromName(listViewItemModule.Text)).OuterHtml);
                }

                // Get relative drop location
                Point htmlEditorCorner = htmlEditor1.PointToScreen(new Point(0, 0));
                int   X = e.X - htmlEditorCorner.X;
                int   Y = e.Y - htmlEditorCorner.Y;

                // Get element on which module was dropped
                IHTMLElement hoverElem  = htmlEditor1.HtmlDocument2.ElementFromPoint(X, Y);
                IHTMLElement moduleElem = null;

                // If it gets dropped on module, pass its parent element instead
                if (CRestrictedEditDesigner.isModule(hoverElem, out moduleElem))
                {
                    hoverElem = moduleElem;
                }

                if (hoverElem.tagName.Equals("BODY"))
                {
                    Debug.WriteLine("dropped on body");
                    if (hoverElem.innerText == null && hoverElem.innerHTML == null)
                    {
                        htmlEditor1.LoadDocument("<body>" + input + "</body>");
                    }
                    else
                    {
                        htmlEditor1.LoadDocument("<body>" + hoverElem.innerHTML + input + "</body>");
                    }
                }
                else
                {
                    Debug.WriteLine("dropped on " + hoverElem.tagName);

                    //Mshtml deletes <module> in element load,
                    //uhm so it has to be converted to HtmlAgilityPack.HtmlDocument
                    //and then back
                    String  guid = Guid.NewGuid().ToString();
                    Boolean idChanged;
                    if (hoverElem.id == null)
                    {
                        hoverElem.id = guid;
                        idChanged    = true;
                    }
                    else
                    {
                        guid      = hoverElem.id;
                        idChanged = false;
                    }

                    // Get wanted element and modify its content
                    HtmlAgilityPack.HtmlDocument htmlDoc = HTMLDocumentConverter.mshtmlDocToAgilityPackDoc(htmlEditor1.HtmlDocument2);
                    HtmlAgilityPack.HtmlNode     node    = htmlDoc.GetElementbyId(guid);

                    // Dont remove id if it was there before
                    if (idChanged)
                    {
                        node.Attributes.Remove("id");
                    }

                    // Need to create element, because HtmlNode dont have OuterHtml settable
                    HtmlNode addedModulesNode = htmlDoc.CreateElement("div");
                    addedModulesNode.InnerHtml = input;

                    try
                    {
                        // Well, this sometimes fails.. god knows why
                        htmlDoc.DocumentNode.InsertAfter(addedModulesNode, node);
                    }
                    catch (Exception)
                    {
                        // So if it fails, add module in the end of parent module
                        node.ParentNode.InnerHtml += input;
                    }

                    // And back to IHTMLDocument
                    htmlEditor1.LoadDocument("<body>" + htmlDoc.DocumentNode.InnerHtml + "</body>");
                }
            }
        }