zoukankan      html  css  js  c++  java
  • 导入和导出任务列表

    Visual Studio的IDE可以用任务列表保存我们在项目进展期间的一些信息。我个人也很喜欢用。但默认情况下是没有办法将这些信息保存起来的,更谈不上我们把它导出其他的格式了。

    image

    为此,我专门写了两个宏去做这个事情

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports System.Diagnostics
    Imports System.Windows.Forms
    Imports System.IO
    Imports System.Xml
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    '导入和导出用户定义任务列表的宏模块
    '作者:陈希章
    '''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Module TaskManagementModule
        Public Class WinWrapper
            Implements System.Windows.Forms.IWin32Window

            Overridable ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
                Get
                    Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd)
                    Return iptr
                End Get
            End Property
        End Class
        <STAThread()> _
        Public Sub ExportTaskList()
            Dim winptr As New WinWrapper
            Dim dialog As New SaveFileDialog

            dialog.Filter = "任务列表(*.XML)|*.XML"
            dialog.Title = "保存为..."
            If dialog.ShowDialog(winptr) = DialogResult.OK Then
                Dim fs As New FileStream(dialog.FileName, FileMode.OpenOrCreate)
                Dim xw As New XmlTextWriter(fs, System.Text.Encoding.UTF8)
                xw.WriteStartDocument()
                xw.WriteStartElement("TaskList")
                For Each task As TaskItem In DTE.ToolWindows.TaskList.TaskItems
                    xw.WriteStartElement("TaskItem")
                    xw.WriteStartElement("Category")
                    xw.WriteCData(task.Category)
                    xw.WriteEndElement()

                    xw.WriteStartElement("SubCategory")
                    xw.WriteCData(task.SubCategory)
                    xw.WriteEndElement()

                    xw.WriteStartElement("Description")
                    xw.WriteCData(task.Description)
                    xw.WriteEndElement()

                    xw.WriteEndElement()
                Next
                xw.WriteEndElement()
                xw.Close()

            End If
        End Sub
        <STAThread()> _
        Public Sub ImportTaskList()
            Dim winptr As New WinWrapper
            Dim dialog As New OpenFileDialog

            dialog.Filter = "任务列表(*.XML)|*.XML"
            dialog.Title = "打开任务列表"
            If dialog.ShowDialog(winptr) = DialogResult.OK Then

                Dim doc As New XmlDocument()
                doc.Load(dialog.FileName)

                For Each node As XmlNode In doc.SelectNodes("TaskList/TaskItem")
                    Dim category As String = node.SelectSingleNode("Category").InnerText
                    Dim subcategory As String = node.SelectSingleNode("SubCategory").InnerText
                    Dim description As String = node.SelectSingleNode("Description").InnerText

                    DTE.ToolWindows.TaskList.TaskItems.Add(category, subcategory, description)
                Next

            End If
        End Sub
    End Module

    以上代码只是一个示范,还可以进一步细化。因为任务有好几种类型:用户任务,快捷方式(书签),注释(TODO)等等

     

    导出的XML文件大致如下

    image

    最后,我可以把这两个宏添加到解决方案的快捷菜单中去

    image

  • 相关阅读:
    【转载】 c++中static的用法详解
    ROS学习 Python读写文本文件
    (论文分析) Machine Learning -- Learning from labeled and unlabeled data
    (论文分析) 图像相似度和图像可见性分析
    (论文分析) Machine Learning -- Support Vector Machine Learning for Interdependent and Structured Output Spaces
    (论文分析) Object Detection-- Discriminatively Trained Part Based Models
    (论文分析) Machine Learning -- Predicting Diverse Subsets Using Structural SVMs
    (论文分析) Machine Learning -- Online Choice of Active Learning Algorithms
    (论文分析) Object Detection -- Class-Specific Hough Forests for Object Detection
    (论文分析) Object Detection -- A Boundary Fragment Model for Object Detection
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1271980.html
Copyright © 2011-2022 走看看