// Items events
        void pCombo_EditDone(object sender, EventArgs e)
        {
            ComboBox pCombo = (ComboBox)sender;

            Debug.WriteLine(pCombo.DroppedDown);

            ListViewEx_EventArgs evArg = (ListViewEx_EventArgs)pCombo.Tag;

            if (evArg != null)
            {
                evArg.strPrevValue   = evArg.lvSubItem.Text;
                evArg.lvSubItem.Text = pCombo.Text;
                subArgs = evArg;
                // For handler
                if (pCombo.DroppedDown == false)
                {
                    EventHandler handler = this.ListSubItemChanged;
                    if (handler != null)
                    {
                        handler(this, evArg);
                        if (evArg.Cancel)
                        {
                            evArg.lvSubItem.Text = evArg.strPrevValue;
                        }
                    }

                    //pCombo.Visible = false;
                    //pCombo.Parent.Focus();
                    pEditControl = null;
                }
            }
        }
        void MFAttributesList_ListSubItemChanged(object sender, EventArgs e)
        {
            ListViewEx_EventArgs lvArg = (ListViewEx_EventArgs)e;

            if (lvArg.nSubItem == 0)
            {
                // Add subitem for value
                lvArg.lvItem.SubItems.Add("");
            }
            else
            {
                // Update attribute
                string sPrefix = (string)lvArg.lvItem.Tag;
                string sName   = sPrefix + lvArg.lvItem.SubItems[0].Text;
                string sValue  = lvArg.lvItem.SubItems[1].Text;


                // Check for new element
                int    bHave = 0;
                string sOldValue;
                m_pMFProps.PropsGet(sName, out sOldValue);

                string sDefValue;
                m_pMFProps.PropsInfoGet(sName, eMInfoType.eMIT_Default, out sDefValue);

                // Check for remove attributes
                if (sValue == "" && bHave == 1)
                {
                    m_pMFProps.PropsRemove(sName);

                    lvArg.lvItem.SubItems[1].Text      = sDefValue;
                    lvArg.lvItem.SubItems[1].ForeColor = Color.Gray;
                }
                else
                {
                    m_pMFProps.PropsSet(sName, sValue);

                    lvArg.lvItem.SubItems[1].ForeColor = Color.Black;

                    if (bHave == 0)
                    {
                        UpdateList();
                    }
                    else if (sValue == "" || sValue == sDefValue)
                    {
                        lvArg.lvItem.SubItems[1].Text      = sDefValue;
                        lvArg.lvItem.SubItems[1].ForeColor = Color.Gray;
                    }
                }
            }
        }
Example #3
0
        void MFAttributesList_ListSubItemChanged(object sender, EventArgs e)
        {
            ListViewEx_EventArgs lvArg = (ListViewEx_EventArgs)e;

            XDocument xDocument = null;

            try
            {
                xDocument = XDocument.Load(m_strPresetsPath);
            }
            catch { }

            if (lvArg.nSubItem == 0)
            {
                // Add subitem for value
                string strProps;
                m_pMFHTML.PropsGet("", out strProps);
                lvArg.lvItem.SubItems.Add(strProps); // Props
                lvArg.lvItem.SubItems.Add("");       // JS

                if (xDocument == null)
                {
                    xDocument = new XDocument(new XElement("Settings"));
                }

                xDocument.Element("Settings").Add(new XElement("Preset", new XAttribute("site", lvArg.lvItem.Text), new XAttribute("props", strProps), new XAttribute("JS", "")));
                xDocument.Save(m_strPresetsPath);

//                 ListViewItem lvItem = Items.Add("<New preset>");
//                 lvItem.Tag = "";
            }
            else
            {
                UpdateHTML(lvArg);

                if (xDocument != null)
                {
                    foreach (var preset in xDocument.Element("Settings").Elements("Preset"))
                    {
                        if (preset.Attribute("site").Value == lvArg.lvItem.Text)
                        {
                            preset.Attribute("props").Value = lvArg.lvItem.SubItems[1].Text;
                            preset.Attribute("JS").Value    = lvArg.lvItem.SubItems[2].Text;

                            xDocument.Save(m_strPresetsPath);
                            break;
                        }
                    }
                }
            }
        }
        private void ListViewEx_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            OnListClick(e.Location);

            ListViewItem         lvItem = Items[SelectedIndices[0]];
            ListViewEx_EventArgs evArg  = new ListViewEx_EventArgs(lvItem, lvItem.SubItems[0], 0, 0); // (ListViewEx_EventArgs)((Control)sender).Tag;
            // For handler
            EventHandler handler = this.ListSubItemOnDoubleClick;

            if (handler != null)
            {
                handler(this, evArg);
            }
        }
        void MFAttributesList_ListSubItemOnStartChange(object sender, EventArgs e)
        {
            ListViewEx_EventArgs lvArg = (ListViewEx_EventArgs)e;

            // Check for separator
            if (lvArg.lvItem.Tag == null)
            {
                lvArg.Cancel = true;
            }

            // Check for property name (edit only if <new name> - one subitem)
            if (lvArg.nSubItem == 0 && lvArg.lvItem.SubItems.Count > 1)
            {
                lvArg.Cancel = true;
            }
        }
        void ListNumChange(NumericUpDown pNumeric)
        {
            ListViewEx_EventArgs evArg = (ListViewEx_EventArgs)pNumeric.Tag;

            evArg.strPrevValue   = evArg.lvSubItem.Text;
            evArg.lvSubItem.Text = pNumeric.Value.ToString();

            // For handler
            EventHandler handler = this.ListSubItemChanged;

            if (handler != null)
            {
                handler(this, evArg);
                if (evArg.Cancel)
                {
                    evArg.lvSubItem.Text = evArg.strPrevValue;
                }
            }
        }
        private void ListTextChange(Control pText)
        {
            ListViewEx_EventArgs evArg = (ListViewEx_EventArgs)pText.Tag;

            if (evArg.lvSubItem.Text != pText.Text)
            {
                evArg.strPrevValue   = evArg.lvSubItem.Text;
                evArg.lvSubItem.Text = pText.Text;

                // For handler
                EventHandler handler = this.ListSubItemChanged;
                if (handler != null)
                {
                    handler(this, evArg);
                    if (evArg.Cancel)
                    {
                        evArg.lvSubItem.Text = evArg.strPrevValue;
                    }
                }
            }
        }
Example #8
0
        private void UpdateHTML(ListViewEx_EventArgs lvArg, bool _bPageLoad = false)
        {
            string strSite = lvArg.lvItem.SubItems[0].Text;
            string strXML  = lvArg.lvItem.SubItems[1].Text;
            string strJS   = lvArg.lvItem.SubItems[2].Text;

            string strCurrURL;

            m_pMFHTML.PropsGet("current_url", out strCurrURL);

            bool bTheSameURL = false;

            if (strCurrURL != null)
            {
                bTheSameURL = strCurrURL.Contains(strSite);
            }

            if (bTheSameURL || _bPageLoad)
            {
                if (_bPageLoad)
                {
                    m_pMFHTML.BrowserPageLoad(strSite);
                }

                m_pMFHTML.PropsSet("", strXML);

                if (!String.IsNullOrEmpty(strJS))
                {
                    m_pMFHTML.BrowserJavascriptExecute(strJS);
                }

                EventHandler handler = this.OnPropsUpdated;
                if (handler != null)
                {
                    handler(this, null);
                }
            }
        }
        void pControl_DoubleClick(object sender, EventArgs e)
        {
            Control pControl = (Control)sender;

            if (pControl.Tag != null)
            {
                // e.g. Browse for file
                try
                {
                    ListViewEx_EventArgs pArg    = (ListViewEx_EventArgs)pControl.Tag;
                    FileDialog           pDialog = (FileDialog)pArg.Tag;
                    if (pDialog.ShowDialog() == DialogResult.OK)
                    {
                        if (pDialog.FileName != null)
                        {
                            pControl.Text = pDialog.FileName;
                            pControl_Leave(sender, e);
                        }
                    }
                }
                catch (System.Exception) { }
            }
        }
        public bool BeginEdit(int nRow, int nCol)
        {
            if (nRow < 0 || nRow >= Items.Count ||
                nCol < 0 || nCol >= Items[nRow].SubItems.Count)
            {
                return(false);
            }

            ListViewItem lvItem = Items[nRow];

            EnsureVisible(nRow);

            Rectangle rcBounds = lvItem.SubItems[nCol].Bounds;

            if (nCol == 0 && lvItem.SubItems.Count > 1)
            {
                // Special fix for first column -> all item width returned
                rcBounds.Width = lvItem.SubItems[1].Bounds.Left - 1;
            }

            ListViewEx_EventArgs pArg = new ListViewEx_EventArgs(lvItem, lvItem.SubItems[nCol], nRow, nCol);

            // Event for cancel
            {
                EventHandler handler = this.ListSubItemOnStartChange;
                if (handler != null)
                {
                    handler(this, pArg);
                    if (pArg.Cancel)
                    {
                        return(false);
                    }
                }
            }

            // Check object type
//             if (Columns[nCol].Tag != null && Columns[nCol].Tag.GetType().Name == "ComboBox")
//             {
//                 try
//                 {
//                     ComboBox pCombo = (ComboBox)lvItem.SubItems[nCol].Tag;
//
//                     if (pCombo.Items.Count > 1)
//                     {
//                         pCombo.Bounds = rcBounds;
//                         pCombo.Visible = true;
//                        // pCombo.Focus(); // Some flickering in ListView if Focused() TODO: Fix
//                         pCombo.DroppedDown = true;
//                     }
//
//                     pEditControl = pCombo;
//                 }
//                 catch (System.Exception) { }
//             }
//             else
            {
                try
                {
                    Control pControl = null;
                    if (lvItem.SubItems[nCol].Tag != null)
                    {
                        try
                        {
                            pControl = (Control)lvItem.SubItems[nCol].Tag;
                        }
                        catch (System.Exception) { }
                    }

                    if (pControl == null && Columns[nCol].Tag != null)
                    {
                        pControl = (Control)Columns[nCol].Tag;
                    }

                    if (pControl == null || !pControl.Enabled)
                    {
                        return(false);
                    }

                    if (pControl.Tag == null && pControl.GetType().Name != "DateTimePicker")
                    {
                        pControl.Leave       += new EventHandler(pControl_Leave);
                        pControl.KeyDown     += new KeyEventHandler(pControl_KeyDown);
                        pControl.DoubleClick += new EventHandler(pControl_DoubleClick);
                    }

                    pControl.Parent = this;
                    pControl.Bounds = rcBounds;
                    if (pControl.GetType().Name != "DateTimePicker")
                    {
                        pControl.Text = lvItem.SubItems[nCol].Text;
                    }
                    else
                    {
                        // Check for current time
                        if (lvItem.SubItems[nCol].Text != "00:00:00")                          // Dirty fix for not reset specified date
                        {
                            pControl.Text = lvItem.SubItems[nCol].Text;
                        }
                        else
                        {
                            // Set current time  + 1 minute forward
                            DateTime dt = DateTime.Now;
                            dt = dt.AddSeconds(-1 * dt.Second);
                            dt = dt.AddMinutes(1.0);

                            pControl.Text = dt.ToString("HH:mm:ss");
                        }
                    }

                    if (pControl.Tag != null)
                    {
                        if (pControl.Tag.GetType().Name != "ListViewEx_EventArgs")
                        {
                            pArg.Tag = pControl.Tag;
                        }
                        else
                        {
                            pArg.Tag = ((ListViewEx_EventArgs)pControl.Tag).Tag;
                        }
                    }
                    pControl.Tag     = pArg;
                    pControl.Visible = true;
                    if (pControl.GetType().Name == "ComboBox")
                    {
                        //((ComboBox) pControl).DropDownHeight = 150;
                        //  ((ComboBox)pControl).DropDown += new EventHandler(pCombo_DropDown);
                        ((ComboBox)pControl).DroppedDown = true;
                        ((ComboBox)pControl).Focus();
                    }
                    else
                    {
                        pControl.Focus();
                    }

                    pEditControl = pControl;
                }
                catch (System.Exception ex) { }
            }

            return(true);
        }