Exemple #1
0
        public childItem FindBeforeSelected <childItem>(DependencyObject obj)
            where childItem : TreeListViewItem
        {
            if (obj is childItem)
            {
                previousContainer = obj as childItem;
            }

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(obj, i);

                if (child != null && child is childItem && (child as childItem).IsSelected)
                {
                    return(previousContainer as childItem);
                }
                else
                {
                    childItem childOfChild = null;
                    if (child is UIElement && (child as UIElement).Visibility == Visibility.Visible)
                    {
                        childOfChild = FindBeforeSelected <childItem>(child);
                    }

                    if (childOfChild != null)
                    {
                        return(childOfChild);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        GetContainerForItemOverride()
        {
            TreeListViewItem newItem = new TreeListViewItem(this);

            this.AddLogicalChild(newItem);
            return(newItem);
        }
Exemple #3
0
 protected override void OnKeyDown(KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         if (e.KeyboardDevice.Modifiers == ModifierKeys.Shift)
         {
             OutlinerCommands.InsertBeforeCurrent.Execute(null, this);
         }
         else
         {
             OutlinerCommands.InsertAfterCurrent.Execute(null, this);
         }
         e.Handled = true;
     }
     if (e.Key == Key.F2)
     {
         OutlinerCommands.FocusEditor.Execute(null, this);
         //FocusEditorForSelectedRow();
         e.Handled = true;
     }
     else if (e.Key == Key.Down)
     {
         found_selected = false;
         TreeListViewItem item = FindNextAfterSelected <TreeListViewItem>(this);
         if (item != null)
         {
             item.Focus();
         }
         e.Handled = true;
     }
     else if (e.Key == Key.Up)
     {
         previousContainer = null;
         TreeListViewItem item = FindBeforeSelected <TreeListViewItem>(this);
         if (item != null)
         {
             item.Focus();
         }
         e.Handled = true;
     }
     else if (e.Key == Key.Delete)
     {
         OutlinerCommands.DeleteCurrentRow.Execute(null, this);
         e.Handled = true;
     }
     else
     if (e.Key == Key.Tab && e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
     {
         OutlinerCommands.IncIndent.Execute(null, this);
         e.Handled = true;
     }
     else
     if (e.Key == Key.Tab && e.KeyboardDevice.Modifiers == ModifierKeys.Shift)
     {
         OutlinerCommands.DecIndent.Execute(null, this);
         e.Handled = true;
     }
 }
Exemple #4
0
        private bool MoveFocusToPreviousContainer()
        {
            previousContainer = null;
            TreeListViewItem item = FindBeforeSelected <TreeListViewItem>(this);

            if (item != null)
            {
                item.Focus();
                return(true);
            }
            return(false);
        }
Exemple #5
0
        internal void MakeFirstEditorFocused()
        {
            TreeListViewItem ti = (ItemContainerGenerator.ContainerFromIndex(0) as TreeListViewItem);

            if (ti != null)
            {
                MyEdit editor = ti.GetEditor(GetViewLastEditorColumnId(), GetLastEditorColumnId(), false) as MyEdit;
                if (editor != null)
                {
                    Keyboard.Focus(editor);
                }
            }
        }
Exemple #6
0
        private bool MoveFocusToNextContainer()
        {
            found_selected = false;
            TreeListViewItem item = FindNextAfterSelected <TreeListViewItem>(this);

            if (item != null)
            {
                item.Focus();
                //item.IsSelected = true;
                return(true);
            }
            return(false);
        }
Exemple #7
0
        internal void SelectRow(OutlinerNote row)
        {
            ItemContainerGenerator t = ItemContainerGeneratorFor(row);

            if (t.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
            {
                t.StatusChanged  += new EventHandler(SelectRow_ContainerGeneratorStatusChanged);
                rowToMakeSelected = row;
            }
            else
            {
                TreeListViewItem tvi = (t.ContainerFromItem(row) as TreeListViewItem);
                tvi.IsSelected = true;
            }
        }
Exemple #8
0
        internal void MakeActive(OutlinerNote newNote, int focusColumnIdx, bool isActiveInlineEdit, EventHandler madeActive)
        {
            __OnMadeActive          = madeActive;
            __ColumnIdxToFocus      = focusColumnIdx;
            __ColumnToFocusIsInline = isActiveInlineEdit;

            ItemContainerGenerator itemContainerGenerator = ItemContainerGeneratorFor(newNote, true);

            if (itemContainerGenerator == null)
            {
                return;
            }

            if (itemContainerGenerator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
            {
                __NoteToMakeActive = newNote;
                itemContainerGenerator.StatusChanged += new EventHandler(itemContainerGenerator_StatusChanged);
                return;
            }

            TreeListViewItem ti = (itemContainerGenerator.ContainerFromItem(newNote) as TreeListViewItem);

            if (ti != null)
            {
                ti.Focus();

                if (__ColumnIdxToFocus == -1)
                {
                    MakeActiveDone(newNote, null);
                }
                else
                {
                    CheckMainWindow();
                    MyEdit editor = ti.GetEditor(__MainWindow.GetViewColumnId(focusColumnIdx), focusColumnIdx, isActiveInlineEdit) as MyEdit;
                    if (editor != null)
                    {
                        Keyboard.Focus(editor);
                        MakeActiveDone(newNote, editor);
                    }
                    else
                    {
                        __NoteToMakeActive = newNote;
                        __TviToMakeActive  = ti;
                        ti.LayoutUpdated  += new EventHandler(ti_LayoutUpdated);
                    }
                }
            }
        }
Exemple #9
0
        void ti_LayoutUpdated(object sender, EventArgs e)
        {
            if (__TviToMakeActive != null)
            {
                MyEdit editor = __TviToMakeActive.GetEditor(GetViewLastEditorColumnId(), GetLastEditorColumnId(), __ColumnToFocusIsInline) as MyEdit;
                if (editor != null)
                {
                    Keyboard.Focus(editor);
                    __TviToMakeActive.LayoutUpdated -= ti_LayoutUpdated;
                    __TviToMakeActive = null;
                    MakeActiveDone(__NoteToMakeActive, editor);
                }
            }

            __NoteToMakeActive = null;
        }
Exemple #10
0
        void itemContainerGenerator_StatusChanged(object sender, EventArgs e)
        {
            ItemContainerGenerator generator = sender as ItemContainerGenerator;

            if (generator == null)
            {
                return;
            }

            if (generator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
            {
                return;
            }

            generator.StatusChanged -= itemContainerGenerator_StatusChanged;
            TreeListViewItem ti = (generator.ContainerFromItem(__NoteToMakeActive) as TreeListViewItem);

            if (ti == null)
            {
                __NoteToMakeActive = null;
            }
            else
            {
                ti.Focus();

                if (__ColumnIdxToFocus == -1)
                {
                    MakeActiveDone(__NoteToMakeActive, null);
                    __NoteToMakeActive = null;
                }
                else
                {
                    MyEdit editor = ti.GetEditor(GetViewLastEditorColumnId(), GetLastEditorColumnId(), __ColumnToFocusIsInline) as MyEdit;
                    if (editor != null)
                    {
                        Keyboard.Focus(editor);
                        MakeActiveDone(__NoteToMakeActive, editor);
                        __NoteToMakeActive = null;
                    }
                    else
                    {
                        __TviToMakeActive = ti;
                        ti.LayoutUpdated += new EventHandler(ti_LayoutUpdated);
                    }
                }
            }
        }
Exemple #11
0
        public static TreeListViewItem GetContainerForItem(TreeListView view, OutlinerNote note)
        {
            ItemContainerGenerator generator = view.ItemContainerGeneratorFor(note);

            if (generator == null)
            {
                return(null);
            }

            TreeListViewItem container = generator.ContainerFromItem(note) as TreeListViewItem;

            if (container == null)
            {
                return(null);
            }

            return(container);
        }
Exemple #12
0
        internal void MakeNextOrPrevSelection()
        {
            found_selected = false;
            TreeListViewItem item = FindNextAfterSelected <TreeListViewItem>(this);

            if (item != null)
            {
                item.Focus();
                return;
            }

            previousContainer = null;
            item = FindBeforeSelected <TreeListViewItem>(this);
            if (item != null)
            {
                item.Focus();
            }
        }
Exemple #13
0
        public ItemContainerGenerator ItemContainerGeneratorFor(object SelectedItem, bool doWait)
        {
            if (SelectedItem == null)
            {
                return(null);
            }

            OutlinerNote Note = (SelectedItem as OutlinerNote);

            if (Note.Parent.IsRoot)
            {
                return(ItemContainerGenerator);
            }
            else
            {
                ItemContainerGenerator ig = ItemContainerGeneratorFor(Note.Parent);

                if (ig != null)
                {
                    if (ig.Status != GeneratorStatus.ContainersGenerated && doWait)
                    {
                        for (int limit = 0; limit < 100; limit++)
                        {
                            if (ig.Status == GeneratorStatus.ContainersGenerated)
                            {
                                break;
                            }

                            app.DoEvents();
                            Thread.Sleep(10);
                        }
                    }

                    TreeListViewItem tvi = (ig.ContainerFromItem(Note.Parent) as TreeListViewItem);
                    if (tvi != null)
                    {
                        return(tvi.ItemContainerGenerator);
                    }
                }
                return(null);
            }
        }
Exemple #14
0
        private void FocusEditorForSelectedRow()
        {
            if (SelectedItem != null)
            {
                ItemContainerGenerator itemGenerator = ItemContainerGeneratorFor(SelectedItem);

                //BUG: Почему здесь иногда бывает null - не ясно
                if (itemGenerator != null)
                {
                    TreeListViewItem li = itemGenerator.ContainerFromItem(SelectedItem) as TreeListViewItem;
                    if (li != null)
                    {
                        MyEdit edit = li.GetEditor(GetViewLastEditorColumnId(), GetLastEditorColumnId(), false) as MyEdit;
                        if (edit != null)
                        {
                            Keyboard.Focus(edit);
                        }
                    }
                }
            }
        }
Exemple #15
0
        void SelectRow_ContainerGeneratorStatusChanged(object sender, EventArgs e)
        {
            ItemContainerGenerator icg = sender as ItemContainerGenerator;

            if (icg.Status == System.Windows.Controls.Primitives.GeneratorStatus.GeneratingContainers)
            {
                return;
            }

            icg.StatusChanged -= SelectRow_ContainerGeneratorStatusChanged;
            if (rowToMakeSelected == null)
            {
                return;
            }

            TreeListViewItem tvi = icg.ContainerFromItem(rowToMakeSelected) as TreeListViewItem;

            if (tvi != null)
            {
                tvi.IsSelected    = true;
                rowToMakeSelected = null;
            }
        }