Beispiel #1
0
 private void FormMain_DragDrop(object sender, DragEventArgs e)
 {
     Cursor = Cursors.WaitCursor;
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         rootFile = new CodeFolder();
         rootFile.File = "全部";
         rootFile.Progress += new ProgressEventHandler(rootFile_Progress);
         progressPanel.Show(treeGridView);
         foreach (string file in files)
         {
             AbstractCodeFile codeFile = CodeFileFactory.Create(file);
             if (null != codeFile)
             {
                 codeFile.Parent = rootFile;
             }
         }
         rootFile.Count();
         progressPanel.Hide();
         rootFile.Sort();
         SetTreeView();
         //OutputCount();
         SetDataGridViewValue();
     }
     Cursor = Cursors.Default;
 }
Beispiel #2
0
        private string GenerateMessage(AbstractCodeFile codeFile)
        {
            StringBuilder message = new StringBuilder();
            message.AppendLine(codeFile.File);
            message.Append(GenerateMessage(codeFile.CodeLineCount));

            foreach (AbstractCodeFile includeCodeFile in codeFile.IncludeFiles)
            {
                message.Append(GenerateMessage(includeCodeFile));
            }

            return message.ToString();
        }
Beispiel #3
0
        private void SetTreeView(AbstractCodeFile codeFile, TreeGridNode parentNode)
        {
            TreeGridNode newNode = parentNode.Nodes.Add(Path.GetFileName(codeFile.File));
            newNode.Tag = codeFile;

            if (codeFile is CodeFolder)
            {
                newNode.ImageIndex = this.treeGridView.ImageList.Images.IndexOfKey("folderOpen");
            }
            else
            {
                ImageList.ImageCollection imageList = this.treeGridView.ImageList.Images;
                string imageKey = Path.GetExtension(codeFile.File);
                if (!imageList.ContainsKey(imageKey))
                {
                    Bitmap icon = IconHelper.GetBitmap(codeFile.File);

                    imageList.Add(imageKey, icon);
                }
                newNode.ImageIndex = this.treeGridView.ImageList.Images.IndexOfKey(imageKey);
            }

            foreach (AbstractCodeFile item in codeFile.IncludeFiles)
            {
                SetTreeView(item, newNode);
            }
        }
Beispiel #4
0
 private DataGridViewRow SetDataGridViewValue(AbstractCodeFile codeFile, DataGridViewRow row)
 {
     CodeLineCount countObj = codeFile.CodeLineCount;
     row.Tag = codeFile;
     row.Cells["colFile"].Value = Path.GetFileName(codeFile.File);
     row.Cells["colTotal"].Value = countObj.Total;
     int fixedCount = countObj.Total;
     foreach (ListViewItem item in listViewInclude.Items)
     {
         PropertyInfo info = item.Tag as PropertyInfo;
         int count = (int)info.GetValue(countObj, null);
         row.Cells["col" + info.Name].Value = count;
         if (!item.Checked)
         {
             fixedCount -= count;
         }
     }
     row.Cells["colFixedCount"].Value = fixedCount;
     return row;
 }
Beispiel #5
0
 private void Sort(AbstractCodeFile codeFile)
 {
     codeFile.IncludeFiles.Sort((item1, item2) =>
     {
         if (item1.GetType().FullName.Equals(item2.GetType().FullName))
         {
             return string.Compare(Path.GetFileName(item1.File), Path.GetFileName(item2.File), true);
         }
         else if (item1 is NormalCodeFile)
         {
             return 1;
         }
         else if (item2 is NormalCodeFile)
         {
             return -1;
         }
         return 0;
     });
     foreach (AbstractCodeFile subCodeFile in codeFile.IncludeFiles)
     {
         Sort(subCodeFile);
     }
 }
Beispiel #6
0
        /// <summary>
        /// 触发Progress事件
        /// </summary>
        /// <param name="codeFile">当前正在处理的文件对象</param>
        protected void OnProgress(AbstractCodeFile codeFile)
        {
            if (null != this.Progress)
            {
                ProgressEventArgs args = new ProgressEventArgs();
                AbstractCodeFile subFile = codeFile.Parent;
                if (null == subFile)
                {
                    args.MainMessage = Path.GetFileName(codeFile.File);
                }
                else
                {
                    AbstractCodeFile mainFile = subFile.Parent;
                    if (null == mainFile)
                    {
                        args.MainMessage = Path.GetFileName(codeFile.File);
                        args.MainMaximum = subFile.IncludeFiles.Count;
                        args.MainValue = subFile.IncludeFiles.IndexOf(codeFile) + 1;
                    }
                    else
                    {
                        args.SubMessage = Path.GetFileName(codeFile.File);
                        args.SubMaximum = subFile.IncludeFiles.Count;
                        args.SubValue = subFile.IncludeFiles.IndexOf(codeFile) + 1;

                        args.MainMessage = Path.GetFileName(subFile.File);
                        args.MainMaximum = mainFile.IncludeFiles.Count;
                        args.MainValue = mainFile.IncludeFiles.IndexOf(subFile) + 1;
                    }
                }
                Progress(codeFile, args);
            }
        }