Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Professional Visual Studio 2005 (2006) [eng]

.pdf
Скачиваний:
132
Добавлен:
16.08.2013
Размер:
21.9 Mб
Скачать

Chapter 55

Private Sub ThisDocument_Startup(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles Me.Startup

AddCompanySmartTag()

DocumentSummary.Select()

Me.ActionsPane.Controls.Add(MainPane)

MainPane.HeadingAreaRef = DocumentHeading

End Sub

9.It’s now time to add the conditional Actions Pane control. Add it to the project just as you did for the MainActions component, this time naming it CompanyNameActions.vb. Add a Button and a ListView to the design surface of the new Actions Pane component and set the

BackColor of the component to SteelBlue to differentiate it from the other Actions Pane contents. Set the following properties for the objects:

Button1.Name: InsertNames

Button1.Text: Insert Name(s)

ListView1.Name: NameList

ListView1.MultiSelect: True

The final design layout for the CompanyNameActions component should look like what is shown in Figure 55-16.

Figure 55-16

10.You’re going to enable the user to select names from the ListView (once it’s populated with data) and then click the InsertNames button. Add an event handler for the Click event of the InsertNames button and ensure that the user has first selected some items from the list. If they haven’t, display a message letting them know that the function cannot work unless they first select items from the list, and then set the focus of Microsoft Word to the NameList ListView control. You can do this in exactly the same way you would if you were building a Windows Forms application:

Private Sub InsertNames_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles InsertNames.Click

If NameList.SelectedItems.Count > 0 Then

‘ code to add information to the table will go here

Else

MessageBox.Show(“You must first select an entry in the list”) NameList.Focus()

End If End Sub

796

Visual Studio Tools for Office

Once you have determined that items have been selected, iterate through the SelectedItems collection of the NameList object and add a row to the table for each item, setting the first cell in the row to the name of the company, and putting some placeholder text in the second cell. Your final subroutine should look like the following listing:

Private Sub InsertNames_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles InsertNames.Click

If NameList.SelectedItems.Count > 0 Then

For Each NameToInsert As ListViewItem In NameList.SelectedItems With Globals.ThisDocument.Tables(1)

.Rows.Add()

.Rows(.Rows.Count).Cells(1).Range.Text = NameToInsert.Text

.Rows(.Rows.Count).Cells(2).Range.Text = “Put information here” End With

Next

Else

MessageBox.Show(“You must first select an entry in the list”) NameList.Focus()

End If End Sub

11.You’re almost done. The only tasks left are to connect the CompanyNameActions component to the document and write some code to populate the ListView control. Open the ThisDocument.vb code module and define the CompanyNameActions object at the top of the class. Again, because you don’t need to intercept any events, just define it as a regular object:

Private TableAreaPane As New CompanyNameActions

12.Rather than being visible at all times, the TableAreaPane object will only be shown when the user is currently editing the table in the document. To determine when the user is within a bookmarked area, you can use the Selected and Deselected events. Add event handler routines for both events to add and remove the TableAreaPane to the ActionsPane.Controls collection as appropriate. The following code shows you how this can be achieved:

Private Sub TableArea_Selected(ByVal sender As Object, _

ByVal e As Microsoft.Office.Tools.Word.SelectionEventArgs) Handles _ TableArea.Selected

Me.ActionsPane.Controls.Add(TableAreaPane)

End Sub

Private Sub TableArea_Deselected(ByVal sender As Object, _

ByVal e As Microsoft.Office.Tools.Word.SelectionEventArgs) Handles _ TableArea.Deselected

Me.ActionsPane.Controls.Remove(TableAreaPane)

End Sub

13.This will display the TableAreaPane object when the user places the cursor inside the bookmarked table of the document, so the only task left is to populate the ListView. You’ll do this by directly accessing the NameList control within the TableAreaPane object from the document, which demonstrates how you can access properties and controls in the Actions Pane components attached to a document.

797

Chapter 55

The information you’ll add to the ListView will come from the smart tag action you left earlier, SaveCompanyName. Add an event handler for the Click event of SaveCompanyName and add the contents of e.Text (which contains the text that was recognized) to the NameList control’s Items collection. When completed, this subroutine appears as follows:

Sub SaveCompanyName_Click(ByVal sender As Object, _

ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) Handles _ SaveCompanyName.Click

TableAreaPane.NameList.Items.Add(e.Text)

End Sub

14.Run the project by pressing F5. This time, when Microsoft Word first starts, you’ll be presented with a rich interface containing not only the bookmarked areas and Windows Forms controls in the document itself, but also an Actions Pane area populated with the main Actions Pane control you defined (see Figure 55-17).

Figure 55-17

15.Perform the following actions:

Type information into the summary area, making sure you include the company names that were included in the Terms collection of the recognizer.

Open the smart tag menu for a recognized term and select the Display information about [companyname] action to see how smart tags can interact with the user.

Open the smart tag menu for a recognized term and select the Save [companyname] to name list action to save the string to the ListView (which is initially invisible).

798

Visual Studio Tools for Office

Change the heading to different length text strings, and click the Format Document button in the main Actions pane to see how it affects the table area formatting.

Change the heading to include the word Wrox, and again click the Format Document button to see how it affects the heading’s style.

Enter information in the TextBox control on the document and click the associated Save Author Name button. Use the File Properties menu to confirm that the built-in property of the document was indeed set (see Figure 55-18).

Figure 55-18

Enter information in the TextBox control in the main Actions pane and click its associated Save Properties button and again check the File Properties menu to check the property’s value.

Place the cursor anywhere in the table area of the document. The secondary Actions Pane component should be added to the Document Actions pane of Microsoft Word, underneath the other Actions pane. You can see which one is which by the different background colors you set.

Select several names from the ListView. These were added when you used the Save [companyname] to name list action earlier.

Click the Insert Name(s) button to automatically add additional rows to the table and populate them with data sourced from the list.

Figure 55-19 shows the document with formatting applied, multiple smart tag terms recognized and their actions performed, and the Insert Name(s) function used to add rows to the table. Note how users can select multiple companies in the ListView and how the Document Actions pane can accommodate multiple Actions pane controls concurrently.

799

Chapter 55

Figure 55-19

Summar y

This chapter introduced you to the major new features in Visual Studio Tools for Office 2005. It is no longer difficult to build feature-rich applications using Word and Excel because now they are fully integrated into the Visual Studio 2005 development environment, enabling you to create .NET solutions that can customize the appearance of the user interface with your own components in both the application and the document. This enables you to have unprecedented control over how end users interact with Word and Excel.

In addition, Outlook is now also supported, with a project template providing the initial code that is required to hook into its complex object model. In conclusion, VSTO 2005 is an excellent resource for Office developers.

800

Visual Studio Team System

In the past, one of the limitations of Visual Studio was that it did not provide support for enter- prise-level development. For example, there was no way to track requirements or bugs, no built-in test engine, and no support for code or performance analysis. Visual Studio Team System gives organizations a single tool that can be used to support the entire software life cycle. This chapter examines the additional features only available in the Team System versions of Visual Studio 2005. In addition, you’ll also learn how the Team Foundation Server provides an essential tool for managing software projects.

Team System Editions

There are three editions of Team System that enable the functionality of Visual Studio Team System to be tailored for the role that an individual plays in the software development team. The three editions target architects, developers, and testers. Visual Studio Team Suite is the fourth edition, which incorporates all of the functionality found within the other editions. The following sections cover the functionality specific to those editions.

For Everyone

Much of the functionality provided by Team System makes use of the Team Foundation Server — a server-based product that combines the document management functions of SharePoint with the data storage capability of SQL Server 2005, and one that is central to the capability of Team System to track work items and act as a source code repository.

Team Explorer

To access information from the Team Foundation Server, you have to establish a connection by clicking Tools Connect to Team Foundation Server. This prompts you through the process of entering information about the location of the server to which you will be connecting. It is possible to

Chapter 56

add multiple servers to this list, although Team System can only be connected to a single server at any given time.

After connecting to a server, you can elect to open one or more existing projects. These projects appear in the Team Explorer, as shown in Figure 56-1. Each project is initially divided into five sections: Source Control, Work Items, Documents, Reports, and Team Builds. If you do not select an existing project, or no projects exist, the Team Explorer will be empty. You can add a new project from the toolbar at the top of the Team Explorer window.

Figure 56-1

Creating a new project requires information such as a name and description for the project. Visual Studio 2005 also prompts you to specify whether you want to create a source control branch for the project and to elect which process template to use; the latter is shown in Figure 56-2.

Team Foundation ships with two process templates called MSF Agile and MSF CMMI; however, other process templates are being built by third parties. The process template you select determines the structure of the project that is created for you. This includes the information contained on a work item, the roles within the team, and a base set of work items to kick off your project.

802

Visual Studio Team System

Figure 56-2

Project Guidance

Both process templates that ship with Visual Studio 2005 include a reference web site that provides project guidance. The project guidance defines roles, work items, processes, and iterations for the development process. Figure 56-3 illustrates the project guidance site for the MSF Agile process template.

The project guidance pages are initially shown immediately after a new Team Project has been created, and can also be opened from the Process Guidance node under Documents in the Team Explorer window.

803

Chapter 56

Figure 56-3

Work Item Tracking

Team Foundation makes extensive use of SQL Server 2005 Reporting Services to provide status information about the project you are working on. A series of predefined Reporting Service queries can be run directly from the Team Explorer window by double-clicking any of the nodes under the Team Queries (refer to Figure 56-1). It is also possible to define your own query that can filter and present data about your project. Examples of this might be the number of tasks completed in the last 24 hours, or the number of tasks currently in progress. Figure 56-4 shows the All Work Items query being run across a new MSF Agile project.

The top portion of the window shows the list of work items that meet the criteria of the query — in this case, all work items. In the lower window the full details of the selected work item are shown and can be edited in place. As work is carried out on a work item, it should be updated so that the status of the project is up-to-date.

804

Visual Studio Team System

Figure 56-4

SharePoint Portal

Although most architects, developers, and testers feel at home using Visual Studio to access information about the project, there are a number of other stakeholders in a project that would not be able to use Visual Studio. When a new project is created in Team Foundation, a SharePoint portal is also created for that project. Included in this portal are all the Reporting Service queries, as well as any documentation that might have been added to the project. This enables project managers, clients, and anyone else

with an interest in the project to access the status of the project at any given time. As the reports are dynamically run across the information within Team Foundation, the information is guaranteed to be current. The project portal can be viewed by right-clicking on the project in the Team Explorer and selecting Show Project Portal. Figure 56-5 illustrates the main page of the portal for a new project. From this page various reports can be run to report on the status of the project.

The project portal controls access to all the documents related to the project other than code files tracked in the source control repository. These can be accessed via the Documents and Lists menu. Information on process guidance, as well as additional predefined reports, can be accessed from the quick launch bar on the left of the screen.

805