예제 #1
0
        private void SearchTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (timer.IsEnabled)
            {
                //stop timer for "no matches" message immediately
                Timer_Tick(null, null);
            }

            if (e == null || e.Key == Key.Return || e.Key == Key.F3)
            {
                ShmVarDataGrid.UnselectAll();
                int i = 0;
                for (i = startIndx; i < ShmVarDataGrid.Items.Count; i++)
                {
                    SharedMemoryVariable currentVar = ShmVarDataGrid.Items[i] as SharedMemoryVariable;
                    if (currentVar.Name.ToUpper().IndexOf(searchTextBox.Text.ToUpper()) == 0)
                    {
                        ShmVarDataGrid.SelectedItem = ShmVarDataGrid.Items[i];
                        startIndx = i + 1;
                        ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);
                        break;
                    }
                }

                if (i == ShmVarDataGrid.Items.Count)
                {
                    //not found
                    startIndx = 0;
                    borderFindNoMatches.Visibility = Visibility.Visible; //instead of a message box, show a hint in the search area
                    timer.Start();                                       //start timer to hide the hint after a short time
                    searchTextBox.Focus();
                }
            }
        }
예제 #2
0
        private void AddNewRow()
        {
            //MessageBox.Show("AddNewRow");       //20130730,SKK
            if (xref == null)
            {
                return;
            }

            //add a new shared memory variable at the end of the list
            xref.GetSharedMemoryManager().AddNewShmVarWithDefaultValue();

            //first set focus
            ShmVarDataGrid.Focus();

            //select the last element of the list
            ShmVarDataGrid.SelectedItem = ListOfShmVariables.Last();

            //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
            DataGridCellInfo cellInfo = new DataGridCellInfo(ShmVarDataGrid.SelectedItem, ShmVarDataGrid.Columns[0]);

            //set the cell to be the active one
            ShmVarDataGrid.CurrentCell = cellInfo;

            //scroll the item into view
            ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);

            //begin the edit
            ShmVarDataGrid.BeginEdit();
        }
예제 #3
0
 private void UserControl_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
 {
     if (!this.IsMouseOver && !contextMenuOpening)
     {
         //if the user clicks somewhere outside of this control while being in edit mode in the data grid, edit mode must be quit
         //ShmVarDataGrid.CancelEdit();
         ShmVarDataGrid.CommitEdit(DataGridEditingUnit.Row, true);
         //we use commit edit, so that the behaviour is the same as clicking somewhere else within the control; this allows committing e.g. an invalid name, but this case must be handled separately anyway (SHM variables must not be used for new connections while the editor is in "invalid" state)
     }
     //MessageBox.Show("UserControl_LostKeyboardFocus");
     contextMenuOpening = false;
 }
예제 #4
0
        private void DeleteSelectedRows()
        {
            if (xref == null)
            {
                return;
            }

            if (ShmVarDataGrid.SelectedItems.Count > 0 && MessageBox.Show("Do you really want to delete all selected variables?", "ViGET V2.0", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            foreach (var item in ShmVarDataGrid.SelectedItems)
            {
                SharedMemoryVariable shmVar = item as SharedMemoryVariable;
                if (shmVar.ConnectionCounter > 0)
                {
                    MessageBox.Show("At least one of the selected variables can not be deleted, because it is connected.\n\nNone of the selected variables will be deleted.", "Delete Not Possible");
                    return;
                }
            }

            int indexOfLastDeletedRow = -1;

            //remove all selected rows(shared memory variables)
            while (ShmVarDataGrid.SelectedItems.Count > 0)
            {
                indexOfLastDeletedRow = ShmVarDataGrid.SelectedIndex;
                xref.GetSharedMemoryManager().RemoveShmVar((ShmVarDataGrid.SelectedItem as SharedMemoryVariable).Name);
            }

            //first set focus
            ShmVarDataGrid.Focus();

            //set selected either the last row or the row below last deleted row
            ShmVarDataGrid.SelectedIndex = Math.Min(indexOfLastDeletedRow, ListOfShmVariables.Count - 1);

            //make the selected item visible
            if (ShmVarDataGrid.SelectedItem != null)
            {
                //then create a new cell info, with the item we wish to edit and the column number of the cell we want in edit mode
                DataGridCellInfo cellInfo = new DataGridCellInfo(ShmVarDataGrid.SelectedItem, ShmVarDataGrid.Columns[0]);
                //set the cell to be the active one
                ShmVarDataGrid.CurrentCell = cellInfo;
                //scroll the item into view
                ShmVarDataGrid.ScrollIntoView(ShmVarDataGrid.SelectedItem);
            }
        }
예제 #5
0
        private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (!(e.OriginalSource is TextBox) && e.Key == Key.Insert)
            {
                AddShmVar_Click(null, null);
                e.Handled = true;
            }

            if (e.Key == Key.Delete)
            {
                if (e.OriginalSource is TextBox)
                {
                    //THIS IS SPECIAL CODE TO FIX AN ISSUE THAT ONLY EXISTS IN THE ViGET FRAMEWORK:
                    //the ViGET frame catches all key down events for the Del key (and others), so it is not reveived any more here
                    //workaround: at least do delete in text boxes on key up of the Del key
                    TextBox textBox = (TextBox)e.OriginalSource;
                    if (textBox.SelectionLength > 0)
                    {
                        //delete selected text
                        int pos = textBox.SelectionStart;
                        textBox.Text = textBox.Text.Substring(0, textBox.SelectionStart) + textBox.Text.Substring(textBox.SelectionStart + textBox.SelectionLength);
                        textBox.Select(pos, 0);
                    }
                    else
                    {
                        //delete one character
                        int pos = textBox.SelectionStart;
                        if (pos < textBox.Text.Length)
                        {
                            textBox.Text = textBox.Text.Substring(0, textBox.SelectionStart) + textBox.Text.Substring(textBox.SelectionStart + 1);
                            textBox.Select(pos, 0);
                        }
                    }
                }
                else
                {
                    //delete variables
                    DelShmVar_Click(null, null);
                    e.Handled = true;
                }
            }

            //ctrl+A for select all
            if (!(e.OriginalSource is TextBox) && e.Key == Key.A)
            {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    ShmVarDataGrid.SelectAll();
                }

                e.Handled = true;
            }

            //ctrl+F for go to search text box
            if (!(e.OriginalSource is TextBox) && e.Key == Key.F)
            {
                if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    //toggle visibility of search panel

                    /*if (panelSearch.Visibility != Visibility.Visible)
                     * {
                     *  panelSearch.Visibility = Visibility.Visible;
                     *  searchTextBox.Focus();
                     * }
                     * else
                     * {
                     *  panelSearch.Visibility = Visibility.Collapsed;
                     * }*/

                    searchTextBox.Focus();
                }

                e.Handled = true;
            }

            //F3 for continue search
            if (!(e.OriginalSource is TextBox) && e.Key == Key.F3)
            {
                SearchTextBox_KeyUp(null, null);
                e.Handled = true;
            }
        }