Пример #1
0
        public void IsTypeDescriptorClosed()
        {
            DraggableListItem    a    = new DraggableListItem();
            ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor();

            desc.AddEvent(new ScriptEventDescriptor("testEvent", true));
        }
Пример #2
0
 private void listViewTabs_ItemDrag(object sender, ItemDragEventArgs e)
 {
     if (e.Item is ListViewItem listViewItem)
     {
         DraggableListItem draggableListItem = _listViewDataSource.FirstOrDefault(x => x.Index == listViewItem.Index);
         if (draggableListItem != null)
         {
             DoDragDrop(draggableListItem, DragDropEffects.Move);
         }
     }
 }
Пример #3
0
        public void Render()
        {
            DraggableListItem b = new DraggableListItem();
            StringWriter      sw;
            ScriptTextWriter  w;

            sw = new StringWriter();
            w  = new ScriptTextWriter(sw);
            ((IScriptComponent)b).RenderScript(w);

            Assert.AreEqual("", sw.ToString(), "A1");
        }
Пример #4
0
        public void TypeDescriptor()
        {
            DraggableListItem    a    = new DraggableListItem();
            ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor();

            Assert.AreEqual(a, desc.ScriptObject, "A1");

            // events
            IEnumerable <ScriptEventDescriptor> events = desc.GetEvents();

            Assert.IsNotNull(events, "A2");

            IEnumerator <ScriptEventDescriptor> ee = events.GetEnumerator();

            Assert.IsTrue(ee.MoveNext(), "A3");
            DoEvent(ee.Current, "propertyChanged", true);
            Assert.IsFalse(ee.MoveNext(), "A4");

            // methods
            IEnumerable <ScriptMethodDescriptor> methods = desc.GetMethods();

            Assert.IsNotNull(methods, "A5");

            IEnumerator <ScriptMethodDescriptor> me = methods.GetEnumerator();

            Assert.IsFalse(me.MoveNext());

            // properties
            IEnumerable <ScriptPropertyDescriptor> props = desc.GetProperties();

            Assert.IsNotNull(props, "A6");

            IEnumerator <ScriptPropertyDescriptor> pe = props.GetEnumerator();

            Assert.IsTrue(pe.MoveNext(), "A7");
            DoProperty(pe.Current, "bindings", ScriptType.Array, true, "Bindings");
            Assert.IsTrue(pe.MoveNext(), "A8");
            DoProperty(pe.Current, "dataContext", ScriptType.Object, false, "");
            Assert.IsTrue(pe.MoveNext(), "A9");
            DoProperty(pe.Current, "id", ScriptType.String, false, "ID");
            Assert.IsTrue(pe.MoveNext(), "A9");
            DoProperty(pe.Current, "data", ScriptType.Object, false, "");
            Assert.IsTrue(pe.MoveNext(), "A10");
            DoProperty(pe.Current, "handle", ScriptType.Object, false, "Handle");
            Assert.IsTrue(pe.MoveNext(), "A11");
            DoProperty(pe.Current, "dragVisualTemplate", ScriptType.Object, false, "");
            Assert.IsFalse(pe.MoveNext(), "A12");
        }
Пример #5
0
        public void Properties()
        {
            DraggableListItem b = new DraggableListItem();

            // default
            Assert.AreEqual("draggableListItem", b.TagName, "A1");
            Assert.AreEqual(null, b.Handle, "A2");

            // getter/setter
            b.Handle = "foo";
            Assert.AreEqual("foo", b.Handle, "A3");

            // null setter
            b.Handle = null;
            Assert.AreEqual(null, b.Handle, "A4");
        }
Пример #6
0
        private void listViewTabs_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Label.Length <= MaxLabelLength && e.Label.Length >= MinLabelLength)
            {
                DraggableListItem listViewItem = _listViewDataSource.FirstOrDefault(x => x.Index == e.Item);
                if (listViewItem != null)
                {
                    listViewItem.Label = e.Label;
                }
                TabDataChanged = true;
                return;
            }

            string textboxMessage = $"Invalid label length. The tab label must be between {MinLabelLength} and {MaxLabelLength} characters long";

            e.CancelEdit = true;
            MessageBox.Show(this, textboxMessage, "Unable to edit label", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Пример #7
0
        private void listViewTabs_DragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(DraggableListItem)))
            {
                return;
            }
            if (listViewTabs.SelectedItems.Count == 0)
            {
                return;
            }

            Point        p = listViewTabs.PointToClient(MousePosition);
            ListViewItem liteViewItemClosestToDropPosition = GetClosestItemInRelationToDropPosition(listViewTabs, p);

            if (!(e.Data.GetData(typeof(DraggableListItem)) is DraggableListItem dragItem))
            {
                return;
            }

            if (liteViewItemClosestToDropPosition == null || liteViewItemClosestToDropPosition.Index == dragItem.Index)
            {
                return;
            }

            int originalIndex = dragItem.Index;
            int newIndex      = liteViewItemClosestToDropPosition.Index;

            if (radioButtonSwitch.Checked)
            {
                DraggableListItem listItem1 = _listViewDataSource.First(x => x.Index == newIndex);
                DraggableListItem listItem2 = _listViewDataSource.First(x => x.Index == originalIndex);

                listItem1.Index = originalIndex;
                listItem2.Index = newIndex;
            }
            else
            {
                int  minIndex  = Math.Min(newIndex, originalIndex);
                int  maxIndex  = Math.Max(newIndex, originalIndex);
                bool leftShift = newIndex > originalIndex;

                if (leftShift)
                {
                    var itemsToShiftIndex = _listViewDataSource.Where(x => x.Index > minIndex && x.Index <= maxIndex).OrderBy(x => x.Index).ToList();
                    DraggableListItem listViewItemToSwitch = _listViewDataSource.First(x => x.Index == minIndex);

                    foreach (DraggableListItem listItem in itemsToShiftIndex)
                    {
                        listItem.Index = listItem.Index - 1;
                    }

                    listViewItemToSwitch.Index = maxIndex;
                }
                else
                {
                    var itemsToShiftIndex = _listViewDataSource.Where(x => x.Index >= minIndex && x.Index < maxIndex).OrderBy(x => x.Index).ToList();
                    DraggableListItem listViewItemToSwitch = _listViewDataSource.First(x => x.Index == maxIndex);

                    foreach (DraggableListItem listItem in itemsToShiftIndex)
                    {
                        listItem.Index = listItem.Index + 1;
                    }

                    listViewItemToSwitch.Index = minIndex;
                }
            }

            TabDataChanged = true;
            _listViewDataSource.Sort();
            LoadTabPageCollection();
        }