public void Add(CloneClass cloneClass)
        {
            CloneResultPageControl pageControl = new CloneResultPageControl();

            pageControl.CloneClass = cloneClass;
            string      resultName  = FormattingHelper.FormatCloneClassName(cloneClass);
            DockControl dockControl = new DockControl(pageControl, resultName);

            documentContainer.AddDocument(dockControl);
            documentContainer.ActiveDocument = dockControl;
        }
        private void UpdateContextMenu()
        {
            contextMenuStrip.Items.Clear();

            if (SelectedCloneGroup != null)
            {
                foreach (Clone clone in SelectedCloneGroup.Clones)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Image  = _cloneBitmap;
                    item.Text   = FormattingHelper.FormatCloneForMenu(clone);
                    item.Tag    = clone;
                    item.Click += openCloneMenuItem_OnClick;
                    contextMenuStrip.Items.Add(item);
                }
            }
        }
        private static string FormatRollupValue(SourceNode node, RollupType rollupType)
        {
            switch (rollupType)
            {
            case RollupType.None:
                return(String.Empty);

            case RollupType.NumberOfClones:
                if (node.NumberOfClones == 0)
                {
                    return(String.Empty);
                }
                return(FormattingHelper.FormatInteger(node.NumberOfClones));

            case RollupType.NumberOfCloneClasses:
                if (node.NumberOfCloneClasses == 0)
                {
                    return(String.Empty);
                }
                return(FormattingHelper.FormatInteger(node.NumberOfCloneClasses));

            case RollupType.NumberOfClonedLines:
                if (node.NumberOfClonedLines == 0)
                {
                    return(String.Empty);
                }
                return(FormattingHelper.FormatInteger(node.NumberOfClonedLines));

            case RollupType.NumberOfLines:
                if (node.LinesOfCode == 0)
                {
                    return(String.Empty);
                }
                return(FormattingHelper.FormatInteger(node.LinesOfCode));

            case RollupType.ClonePercentage:
                if (Math.Abs(node.ClonePercentage - Double.Epsilon) <= Double.Epsilon)
                {
                    return(String.Empty);
                }
                return(FormattingHelper.FormatPercentage(node.ClonePercentage));

            default:
                throw ExceptionBuilder.UnhandledCaseLabel(rollupType);
            }
        }
Beispiel #4
0
        private void UpdateContextMenu(ContextMenuStrip contextMenu, CloneIntersectedItem cloneIntersectedItem)
        {
            contextMenu.Items.Clear();

            if (cloneIntersectedItem == null)
            {
                return;
            }

            List <CloneIntersection> clones = new List <CloneIntersection>(cloneIntersectedItem.Clones);

            clones.Sort(delegate(CloneIntersection x, CloneIntersection y)
            {
                int result = x.Clone.StartLine.CompareTo(y.Clone.StartLine);
                if (result == 0)
                {
                    result = x.Clone.LineCount.CompareTo(y.Clone.LineCount);
                }
                return(result);
            });

            Dictionary <CloneClass, Bitmap> cloneClassBitmaps = new Dictionary <CloneClass, Bitmap>();

            foreach (CloneIntersection cloneIntersection in clones)
            {
                CloneClass cloneClass = cloneIntersection.Clone.CloneClass;

                Bitmap cloneClassBitmap;
                if (!cloneClassBitmaps.TryGetValue(cloneClass, out cloneClassBitmap))
                {
                    cloneClassBitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
                    using (Graphics g = Graphics.FromImage(cloneClassBitmap))
                    {
                        int       height    = GetBoxHeight() - 1;
                        int       width     = cloneClassBitmap.Width - 1;
                        int       top       = (int)Math.Floor(cloneClassBitmap.Height / 2.0 - height / 2.0);
                        Rectangle rectangle = new Rectangle(0, top, width, height);

                        Brush brush = GetCloneIntersectonBrush(cloneIntersection);
                        g.FillRectangle(brush, rectangle);
                        g.DrawRectangle(Pens.Black, rectangle);
                    }
                    cloneClassBitmaps.Add(cloneClass, cloneClassBitmap);
                }

                ToolStripMenuItem cloneItem = new ToolStripMenuItem();
                cloneItem.Text  = FormattingHelper.FormatCloneForMenu(cloneIntersection.Clone);
                cloneItem.Image = cloneClassBitmap;
                contextMenu.Items.Add(cloneItem);

                ToolStripMenuItem openInEditorItem = new ToolStripMenuItem();
                openInEditorItem.Text   = Res.MenuOpenInEditor;
                openInEditorItem.Tag    = cloneIntersection.Clone;
                openInEditorItem.Click += openInEditorToolStripItem_Click;
                cloneItem.DropDownItems.Add(openInEditorItem);

                ToolStripMenuItem findAllOccurencesItem = new ToolStripMenuItem();
                findAllOccurencesItem.Text   = Res.MenuFindAllOccurrences;
                findAllOccurencesItem.Tag    = cloneIntersection.Clone;
                findAllOccurencesItem.Click += findAllOccurencesToolStripItem_Click;
                cloneItem.DropDownItems.Add(findAllOccurencesItem);
            }
        }
        private void UpdateUI()
        {
            CloneDetectiveResult result = CloneDetectiveManager.CloneDetectiveResult;

            switch (CurrentUIState)
            {
            case UIState.NoSolution:
                runToolStripButton.Enabled          = false;
                stopToolStripButton.Enabled         = false;
                settingsToolStripButton.Enabled     = false;
                importToolStripButton.Enabled       = false;
                exportToolStripButton.Enabled       = false;
                closeToolStripButton.Enabled        = false;
                rollupTypeToolStripComboBox.Enabled = false;
                resultTableLayoutPanel.Visible      = false;
                pictureBox.Image     = null;
                runningLabel.Visible = false;
                progressBar.Visible  = false;
                break;

            case UIState.SolutionAndRunning:
                runToolStripButton.Enabled          = false;
                stopToolStripButton.Enabled         = true;
                settingsToolStripButton.Enabled     = false;
                importToolStripButton.Enabled       = false;
                exportToolStripButton.Enabled       = false;
                closeToolStripButton.Enabled        = false;
                rollupTypeToolStripComboBox.Enabled = false;
                resultTableLayoutPanel.Visible      = false;
                pictureBox.Image     = Res.Running;
                runningLabel.Visible = true;
                progressBar.Visible  = true;
                break;

            case UIState.Solution:
                runToolStripButton.Enabled          = true;
                stopToolStripButton.Enabled         = false;
                settingsToolStripButton.Enabled     = true;
                importToolStripButton.Enabled       = true;
                rollupTypeToolStripComboBox.Enabled = true;
                runningLabel.Visible = false;
                progressBar.Visible  = false;
                if (result == null)
                {
                    exportToolStripButton.Enabled       = false;
                    closeToolStripButton.Enabled        = false;
                    rollupTypeToolStripComboBox.Enabled = false;
                    resultTableLayoutPanel.Visible      = false;
                    pictureBox.Image = null;
                }
                else
                {
                    closeToolStripButton.Enabled   = true;
                    resultTableLayoutPanel.Visible = true;
                    switch (result.Status)
                    {
                    case CloneDetectiveResultStatus.Succeeded:
                        exportToolStripButton.Enabled       = true;
                        rollupTypeToolStripComboBox.Enabled = true;
                        pictureBox.Image     = Res.Succeeded;
                        resultLinkLabel.Text = Res.CloneExplorerSucceeded;
                        timeLabel.Text       = String.Format(CultureInfo.CurrentCulture, Res.CloneExplorerTimeStatistic, FormattingHelper.FormatTime(result.UsedTime));
                        memoryLabel.Text     = String.Format(CultureInfo.CurrentCulture, Res.CloneExplorerMemoryStatistic, FormattingHelper.FormatMemory(result.UsedMemory));
                        timeLabel.Visible    = true;
                        memoryLabel.Visible  = true;
                        break;

                    case CloneDetectiveResultStatus.Failed:
                        exportToolStripButton.Enabled       = false;
                        rollupTypeToolStripComboBox.Enabled = false;
                        pictureBox.Image     = Res.Error;
                        resultLinkLabel.Text = Res.CloneExplorerFailed;
                        timeLabel.Visible    = false;
                        memoryLabel.Visible  = false;
                        break;

                    case CloneDetectiveResultStatus.Stopped:
                        exportToolStripButton.Enabled       = false;
                        rollupTypeToolStripComboBox.Enabled = false;
                        pictureBox.Image     = Res.Stopped;
                        resultLinkLabel.Text = Res.CloneExplorerStopped;
                        timeLabel.Visible    = false;
                        memoryLabel.Visible  = false;
                        break;

                    default:
                        throw ExceptionBuilder.UnhandledCaseLabel(result.Status);
                    }
                }
                break;

            default:
                throw ExceptionBuilder.UnhandledCaseLabel(CurrentUIState);
            }

            UpdateTreeView();
        }