예제 #1
0
        /// <summary>
        /// Show context menu.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void dataGridResults_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                _rightClickedCell             = VisualHelper.GetAncestor <DataGridCell>(e.OriginalSource as DependencyObject);
                _menuItemCopyValue.Visibility = (_rightClickedCell != null && _rightClickedCell.Content is TextBlock) ?
                                                System.Windows.Visibility.Visible :
                                                System.Windows.Visibility.Collapsed;

                DataGridRow item = VisualHelper.GetAncestor <DataGridRow>(e.OriginalSource as DependencyObject);
                if (item != null)
                {
                    dataGridResults.SelectedIndex = item.GetIndex();
                    if (dataGridResults.SelectedIndex < dataGridResults.Items.Count - 1)
                    {
                        _contextMenu.PlacementTarget = item;
                        _contextMenu.Placement       = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
                        _contextMenu.IsOpen          = true;
                    }
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }
        /// <summary>
        /// Change behavior of the right mouse button click.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void listBoxItems_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                e.Handled = true;

                CommitHeaderControl item = VisualHelper.GetAncestor <CommitHeaderControl>(e.OriginalSource as DependencyObject);
                if (item != null)
                {
                    int  count      = SelectedCommits.Length;
                    bool isSelected = listBoxItems.SelectedItems.Contains(item);

                    if (!isSelected)
                    {
                        if (count > 1)
                        {
                            listBoxItems.SelectedItems.Clear();
                        }

                        listBoxItems.SelectedItems.Add(item);
                    }
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }
예제 #3
0
 /// <summary>
 /// Execute function that was clicked.
 /// </summary>
 /// <param name="sender">Object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Button button = VisualHelper.GetAncestor <Button>(e.OriginalSource as DependencyObject);
         if (button != null && button.Tag is IFunction)
         {
             (button.Tag as IFunction).Execute();
         }
     }
     catch (Exception err)
     {
         App.HandleException(err);
     }
 }
예제 #4
0
 /// <summary>
 /// Execute function that was clicked.
 /// </summary>
 /// <param name="sender">Object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void MenuItem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MenuItem menuItem = VisualHelper.GetAncestor <MenuItem>(e.OriginalSource as DependencyObject);
         if (menuItem != null && menuItem.Tag is IFunction && (menuItem.Tag as IFunction).IsEnabled)
         {
             (menuItem.Tag as IFunction).Execute();
         }
     }
     catch (Exception err)
     {
         App.HandleException(err);
     }
 }
예제 #5
0
 /// <summary>
 /// Handles execution of the TabItemClose command.
 /// </summary>
 /// <param name="sender">Object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void CloseTabItemCommandExecute(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         TabItem tabItem = VisualHelper.GetAncestor <TabItem>(e.OriginalSource as DependencyObject);
         if (tabItem != null && tabItem.Tag is IDocument)
         {
             CloseDocument(tabItem.Tag as IDocument);
         }
     }
     catch (Exception err)
     {
         App.HandleException(err);
     }
 }
예제 #6
0
 /// <summary>
 /// Handles execution of the TabItemClose command.
 /// </summary>
 /// <param name="sender">Object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void CloseTabItemCommandExecute(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         TabItem tabItem = VisualHelper.GetAncestor <TabItem>(e.OriginalSource as DependencyObject);
         if (tabItem != null)
         {
             INodeManager manager = tabItem.Tag as INodeManager;
             if (manager.Nodes.Count > 0)
             {
                 RemoveManager(manager.Nodes[0]);
             }
         }
     }
     catch (Exception err)
     {
         App.HandleException(err);
     }
 }
예제 #7
0
        /// <summary>
        /// Display the clicked tab item.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Arguments for the event.</param>
        private void ContextMenu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                MenuItem menuItem = e.OriginalSource as MenuItem;
                TabItem  tabItem  = menuItem.Tag as TabItem;

                TabControl tabControl = VisualHelper.GetAncestor <TabControl>(tabItem);
                if (tabControl != null)
                {
                    int index = tabControl.Items.IndexOf(tabItem);
                    if (index != -1)
                    {
                        tabControl.Items.RemoveAt(index);
                        tabControl.Items.Insert(0, tabItem);
                        tabControl.SelectedItem = tabItem;
                    }
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }
예제 #8
0
        /// <summary>
        /// Display context menu.
        /// </summary>
        /// <param name="sender">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void ContentControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Control control = sender as Control;
                control.ContextMenu.Items.Clear();

                TabControl tabControl = VisualHelper.GetAncestor <TabControl>(control);
                if (tabControl != null)
                {
                    List <MenuItem> menuItems = new List <MenuItem>();
                    foreach (TabItem tabItem in tabControl.Items)
                    {
                        TextBlock textBlock = VisualHelper.GetChild <TextBlock>(tabItem.Header as DependencyObject);
                        Image     image     = VisualHelper.GetChild <Image>(tabItem.Header as DependencyObject);

                        if (textBlock != null && !String.IsNullOrWhiteSpace(textBlock.Text))
                        {
                            object header = textBlock.Text;
                            if (image != null)
                            {
                                StackPanel stack = new StackPanel();
                                stack.Orientation = Orientation.Horizontal;
                                stack.Children.Add(new Image()
                                {
                                    Source = image.Source,
                                    Height = image.Height,
                                    Width  = image.Width,
                                    Margin = new Thickness(2)
                                });
                                stack.Children.Add(new TextBlock()
                                {
                                    Text = textBlock.Text,
                                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                                });

                                header = stack;
                            }

                            menuItems.Add(new MenuItem()
                            {
                                Header = header,
                                Tag    = tabItem
                            });
                        }
                    }

                    foreach (MenuItem menuItem in menuItems.OrderBy(mi => mi.Header.ToString()))
                    {
                        control.ContextMenu.Items.Add(menuItem);
                    }
                }

                if (control.ContextMenu.Items.Count > 0)
                {
                    control.ContextMenu.IsEnabled       = true;
                    control.ContextMenu.PlacementTarget = control;
                    control.ContextMenu.Placement       = PlacementMode.Bottom;
                    control.ContextMenu.IsOpen          = true;
                }
            }
            catch (Exception err)
            {
                App.HandleException(err);
            }
        }