This topic describes the steps to add the Print selected pages to the context menu of the pages listing, displayed on the Shell main tab.
Note: this functionality was made standard since the build 2.0.2085. For older builds, perform the steps as explained in this topic.
Prerequisites of this task: you need to have the access to the add-ins sources, an installed and working Visual Studio Express, the ability to compile add-ins and to load them in the database, and the ability to modify configuration files and import then in the database.
The first challenge was to build a script to print selected pages that are not open on the Pages main tab, where the printing is performed by the PDFGenerate script in Fred.vb. So we opened the add-ins solution in the Visual Studio Express and found a similar script in the Edition.vb: Public Overridable Sub PrintEditionPages() 'print selected or all pages of current edition to server If Edition Is Nothing Then Return
Dim optPrint As New Editorial.PrintOptions EditorialClient.PrintOptionsDlg.Show(optPrint, Nothing, Nothing, True, False, String.Empty) Dim confid = optPrint.Id
If confid > 0 Then If Designer.GetSelPageNum() = 0 Then SelectPagesOnly()
Dim idsPages As List(Of Integer) = New List(Of Integer)() For Each page In Designer.GetSelPagesObjs() If page.idAttr > 0 Then idsPages.Add(page.idAttr) Next
FredUtils.PDFGenerateServer(confid, idsPages, Nothing, Nothing) End If End Sub It was clear that the PrintEditionPages script couldn't be used as such, as it relays on some methods, available only on the Editions main tab, but it could be rewritten. So, we copied from it the below part, knowing already that the grayed out lines and parts need to be replaced with something suitable for the Shell main listing: Dim optPrint As New Editorial.PrintOptions EditorialClient.PrintOptionsDlg.Show(optPrint, Nothing, Nothing, True, False, String.Empty) Dim confid = optPrint.Id
If confid > 0 Then If Designer.GetSelPageNum() = 0 Then SelectPagesOnly()
Dim idsPages As List(Of Integer) = New List(Of Integer)() For Each page In Designer.GetSelPagesObjs() If page.idAttr > 0 Then idsPages.Add(page.idAttr) Next
FredUtils.PDFGenerateServer(confid, idsPages, Nothing, Nothing) On the Shell main tab (and on the navigators too), the way to get selected objects is by using this code: Dim selectedObjects As IGenericAttrObjList = Main.GetSelectedObjects If selectedObjects IsNot Nothing AndAlso selectedObjects.Count > 0 Then .... There for we changed the initial part of the new PrintSelectedPages script to be as: Public Overridable Sub PrintSelectedPages() 'v1 on 14/Feb/2014 (BS) - created 'print selected pages to server Dim selectedObjects As IGenericAttrObjList = Main.GetSelectedObjects
If selectedObjects IsNot Nothing AndAlso selectedObjects.Count > 0 Then Dim optPrint As New Editorial.PrintOptions EditorialClient.PrintOptionsDlg.Show(optPrint, Nothing, Nothing, True, False, String.Empty) Dim confid = optPrint.Id
If confid > 0 Then Dim idsPages As List(Of Integer) = New List(Of Integer)() ... The For Each page part was redone as: For Each selectedObject In selectedObjects If (selectedObject.ObjectTypeName = "page") Then If selectedObject.Id > 0 Then idsPages.Add(selectedObject.Id) End If End If Next Therefore, the new complete script is now: Public Overridable Sub PrintSelectedPages() 'v1 on 14/Feb/2014 (BS) - created 'print selected pages to server Dim selectedObjects As IGenericAttrObjList = Main.GetSelectedObjects
If selectedObjects IsNot Nothing AndAlso selectedObjects.Count > 0 Then Dim optPrint As New Editorial.PrintOptions EditorialClient.PrintOptionsDlg.Show(optPrint, Nothing, Nothing, True, False, String.Empty) Dim confid = optPrint.Id
If confid > 0 Then Dim idsPages As List(Of Integer) = New List(Of Integer)()
For Each selectedObject In selectedObjects If (selectedObject.ObjectTypeName = "page") Then If selectedObject.Id > 0 Then idsPages.Add(selectedObject.Id) End If End If Next FredUtils.PDFGenerateServer(confid, idsPages, Nothing, Nothing) End If End If End Sub |
In order to be able to test the script, we closed all GN4 applications, recompiled add-ins, using Visual Studio Express, and then we restarted Fred4. |
The quick test was performed, from the Script Editor, selecting a page on the Pages listing of the Shell main tab, entering the script name in the Command box, selecting the ShellTabItem (CustomFredMainAddIn) context and clicking Execute: the pop-up menu appeared, and that meant the script works. |
The next challenge was to find out where is defined the context menu that shows up when you right-click a page on the Pages listing of the Shell main tab. The idea was to add a new menu entry to it. A quick look to the Script Editor, while the Capture check-box was ticked, shown that the script caller is ShowResultListDesignerContextMenu. Finding all occurrences of the ShowResultListDesignerContextMenu in the entire solution brought two occurrences of the script with than name: one in Shell.vb, and another in Ted.vb. The one in the Shell.vb was a better candidate. Looking at the code, it was clear that it displays the pop-up menu, defined in the directory style, or in base query, or if none of previous is found, then the ResultListPopup. Searching for the ResultListPopup in all configuration files, the only one item got out, but that menu was not the one shown on the Pages listing. Therefore, it was surely defined either in the directory style or in base query. We used the Show Configuration Details command on the Help menu (with the pages listing open), to get to know that the base query that generated it is Fred4Pages. Then, we searched all configuration files for <BaseQuery Name="Fred4Pages" and then we found out that the pop-up menu name is ContextMenuName="PagePopup". Searching for the PagePopup in all configuration files, we found it in Shell4_TabItems.xml, where we added the line: <l:ShellMenuItem Header="Print Selected Pages" CommandParameter="PrintSelectedPages" /> and did some other menu improvements, unrelated to this task. |