Our Rules Tools group in the Process
tab of the Visio ribbon needs to be extended to include our new
features. The features can be viewed in the following screenshot:
There are four new buttons required. They are:
Annotate
Report
Export
Import
These are added to Ribbon.xml and the relevant callbacks are added to the Ribbon class.
The Annotate button is enabled for all diagrams, but the other buttons are only enabled when the Rules Explorer window is open, and I have arranged them on the dropdown menu of a split button.
The OnAction event of the Annotate button checks whether the active page type is a visTypeForeground.
This is because a user may inadvertently be on a reviewer
(visTypeMarkup) or background (visTypeBackground) page when the button
is clicked. This is explained further in the next section.
case "buttonAnnotate":
Globals.ThisAddIn.OnActionAnnotateIssues();
break;
The ThisAddin class has the following method:
public void OnActionAnnotateIssues()
{
ViewModel.VEDocument document = this.documents[Globals.ThisAddIn.Application.ActiveDocument.ID];
if (document != null)
{
// this is our document so call open window
document.OpenAnnotateIssues();
}
}
The VEDocument class has the OpenAnnotateIssues()
method that checks the page type, and whether the user is in markup
mode or not (this is done by checking if the value of a specific cell in
the document's ShapeSheet):
public void OpenAnnotateIssues()
{
Globals.ThisAddIn.VEApp.SelectedVEDocument = this;
//Toggle the annotation
if (Globals.ThisAddIn.VEApp.VisioApplication.ActivePage.Type == Visio.VisPageTypes.visTypeForeground)
if (this.document.DocumentSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject,
(short)Visio.VisRowIndices.visRowDoc,
(short)Visio.VisCellIndices.visDocViewMarkup).ResultIU ==0)
{ this.DisplayIssueMarkup(); }
else
{ this.HideIssueMarkup(); }
else
this.HideIssueMarkup();
}
Both the Export RuleSets and RuleSets Report button will output a single rule set if a rule or rule set item is selected in the Rules Explorer window, or all of the rule sets if a document item is selected. The export method is as follows:
Globals.ThisAddIn.VEApp.SelectedVEDocument.ExportDocument(true, true);
And the report method is called as follows:
Globals.ThisAddIn.VEApp.SelectedVEDocument.ReportDocument(true, false);
The two arguments passed
through are used to decide whether to include rule sets and issues in
the action. Actually, whilst I have provided exporting rule sets and
issues to XML, I have not included a report for issues currently.
Therefore, the second argument for ReportDocument is false. Perhaps, you would like to create a XSL report for issues.
The action for the Import RuleSets button simply checks that a document has been selected in the Rules Explorer before asking for a confirmation of the rule sets in the selected XML document.
if (Globals.ThisAddIn.VEApp.SelectedVEDocument != null)
{
if (System.Windows.MessageBox.Show("Do you want to import the rule sets to " +
Globals.ThisAddIn.VEApp.SelectedVEDocument.DisplayName + "?",
this.GetLabel(control),
System.Windows.MessageBoxButton.YesNo,
System.Windows.MessageBoxImage.Question,
System.Windows.MessageBoxResult.Yes) == System.Windows.MessageBoxResult.Yes)
{
Globals.ThisAddIn.VEApp.SelectedVEDocument.ImportRuleSets();
}
}