VSX: ProjectFlavor-only item VSTemplates? - vsx

In Visual Studio 2005, 2008, and 2010, is it possible to define an Item Template that only appears in the Add Item dialog for projects of a particular ProjectFlavor? I'd rather not clutter all of the other unrelated projects' Add Items dialog if I can help it.
Seems that the <ProjectType>CSharp</ProjectType> is a fixed enumeration and I can't find any place for a ProjectFlavor guid or otherwise.
I don't see any examples of other products showing such restraint, but I want to make sure.
=====
OK, Aaron's tip is very promising but my first attempt is unsuccessful.
In the .vstemplate:
<TemplateData>
<Name>MyProject A File</Name>
<Description>MyProject A File to do stuff</Description>
<Icon>A.ico</Icon>
<TemplateID>TemplateID_A</TemplateID>
<TemplateGroupID>MyTemplateGroupID</TemplateGroupID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
<SortOrder>20</SortOrder>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>Template_A.cs</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">Template_A.cs</ProjectItem>
</TemplateContent>
And on the package.cs:
// [ProvideProjectItem(typeof(MyProjectFactory), "MyTemplateGroupID",
// #"Templates\ProjectItems", 600)] // Took this out.
[ProvideProjectFactory(typeof(MyProjectFactory),
"My Project", "My Project Files (*.csproj);*.csproj",
null, null, #"Templates\Projects",
LanguageVsTemplate = "CSharp",
NewProjectRequireNewFolderVsTemplate = true,
TemplateGroupIDsVsTemplate="MyTemplateGroupID",
TemplateIDsVsTemplate = "TemplateID_A,TemplateID_B")]
public sealed class MyPackage : Package { ... }

Yes this is possible and there are a few item templates "in the box" that do this. For example, you'll notice that the C# or VB item templates for WPF items (Page, Window, FlowDocument, etc...) only appear if you're working with a WPF-flavored project.
The trick is to specify the same TemplateGroupID in each vstemplate file, and then specify this same TemplateGroupID in the registration of your project flavor.

Related

Get shared pages using localized component

I'm currently working on a event handler, which will on save-event, save the latest revision date of the page and it's components into a custom database, and this is working, but i'm facing some performance issues.
Let me give you an example, for how it's working:
If a component is saved/updated (changes are made), then I want to update all pages using this component in my custom database.
Basic blueprint setup:
200 contains components
400 translation publication for components (inherent components from 200)
500 master publication for pages
600 local site publication inherent components from 400 and pages from 500)
So lets say we have component X in 200, this component is included in in a page in 500, X is localized in 400 (let us call it X(l)) and the page in 600 is NOT localized ( i.e it will use the component x(l))
So now to my question:
In my save event handler, i check what pages X(l) are included in , by using :
var filter = new UsingItemsFilter(component.Session)
{
IncludeLocalCopies = true,
ItemTypes = new[] { ItemType.Page }
};
but this will only give me references to pages from 500.
So what i then do (which feels kind of stupid) is to
create a tcm id of all pages in child publications(by looping over them) that inherent this page (now im using some psuedocodelike coding):
foreach(var 500page in foundPages)
foreach(var publication in publications){
if(subject.Session.IsExistingObject(
new TcmUri(page.Id.ItemId,page.Id.ItemType,publication.Id.ItemId)
))
{
someListThatWillContainAllChildPagesFrom500.Add(TheAboveTcmUri);
}
}
And then for each page, check the components in that page, and finally save this state to my custom database.
So the question is, is there a way by to query for all pages, that make use of the localized component, by using the TOM.NET api (no not CoreServiceClient)?
Is there a better way to find child publications of a publication, so I only need to check for pages in the childPublication?
Br Martin
The following code sample should give you the shared items of a specific local/localized item along with the item. BluePrintNodesFilter was introduced in 2013, however in earlier version BluePrintFilter should work in similar way.
SystemManager systemManager = session.SystemManager;
BluePrintNodesFilter filter = new BluePrintNodesFilter(session)
{
BaseColumns = ListBaseColumns.Id,
ForItem = page
};
IEnumerable<BluePrintNode> allNodes = systemManager.GetBluePrintNodes(filter);
IEnumerable<RepositoryLocalObject> sharedAndLocal = (from node in allNodes
where node.Item != null
where node.Item.OwningRepository.Id == page.OwningRepository.Id
select node.Item).ToArray();

How to open text file with the help of button under any form?

I have one text file(Notepad) put under resources node in AX 2012 AOT. Now, my task is to open this file with the help of button under any form.
http://msdn.microsoft.com/en-us/library/cc967403.aspx
Above link is helpful when creating temporary file for writing or reading.
Also, there is a form in AX 2012 named "smmDocuments" in which we can put text files of our use and we can open that file easily from there. I have researched and found that there is a class named "DocuAction" in AX 2012 to perform operations with text files.
But I am unable to understand how that thing is working.
///////////////////
I got it working as:
void clicked()
{
//super();
str sTempPath,
sFileName = "notes.txt";
SysResource::saveToTempFile(SysResource::getResourceNode(resourceStr(flow_for_address_book_txt)), false, "notes.txt");
sTempPath = WinAPI::getTempPath();
WinAPI::shellExecute(sTempPath+sFileName);
}
Thanks Jan B.
You do not describe what actions you want to perform on your file.
Suppose you want to show the file to your user using the default program, then do:
void clicked()
{
SysResource::saveToTempFile(SysResource::getResourceNode(resourceStr(MyImage), false, "notes.txt");
WinAPI::shellExecute("notes.txt");
}
Use a temporary file instead of a hardcoded name.
You may also display the text in a form control:
void clicked()
{
container con = SysResource::getResourceNodeData(SysResource::getResourceNode(resourceStr(MyImage), false, "notes.txt");
infoStringControl.text(conpeek(con,1)); //Not sure how to use the container!
}

Can I have flexible/catchall regions with Tridion XM/New UI/2012 UI

I am putting together a functional design for a site which will aims use the Tridion 2012 UI/XM to manage pages. There are 2 regions on the page, a main content area on the left and a side-bar on the right. Ideally users should be able to drag and drop content into and within these regions. In an ideal world I would like to define the regions along the lines of
Side Bar: any CP for which the CT has the text 'Right' in it.
Main: all other CPs
Looking at the documentation it seems that you need to explicitly use CT/Schema ID pairs to define regions. Is there any possibility to do this in any other way?
At the very least I would like to be able to define that the side bar allows a certain fixed set of CT/Schema ID pairs, but have the main region as a catchall bucket.. Is this possible?
It is also possible that the Side Bar is split into 2 regions, above and below an advertisement. Both regions should allow the same types of CP - as far as I understand this is not possible - is this correct? Are there any ideas for workarounds?
To configure regions that take all Content Types, You need to get Publication AppData and loop through the content types and build your json markup for enabling this.You could write C# TBB which includes on each page template and does this logic, you can define some metadata at CT level which determines which region it will go in and build the Region JSON markup.
Below is the snippet to get all Component types to add in one region. You could change the logic to get only right just by checking the template name.
// get the publication from the engine -- using TemplateBase Util..
Publication thisPub = GetPublication();
XmlElement seAppdata = thisPub.LoadApplicationData("SiteEdit").GetAs<XmlElement>();
XmlNamespaceManager seNsMgr = new XmlNamespaceManager(new NameTable());
seNsMgr.AddNamespace("se", "http://www.sdltridion.com/2011/SiteEdit");
seNsMgr.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
XmlNodeList contentTypes = (XmlNodeList)seAppdata.SelectNodes("//se:ContentTypes/se:ContentType", seNsMgr);
List<String> contentTypeJson = new List<String>();
foreach (XmlNode contentType in contentTypes)
{
string templateId = contentType.SelectSingleNode("se:ComponentTemplate/#xlink:href", seNsMgr).Value;
string componentId = contentType.SelectSingleNode("se:Component/#xlink:href", seNsMgr).Value;
Component thisSchema = (Component)engine.GetObject(componentId);
string schemaId = thisSchema.Schema.Id;
// Add json formated string for Content Types
contentTypeJson.Add(string.Format("{{schema: \"{0}\", template: \"{1}\"}}", schemaId, templateId));
}
// Final Markup - JSON
String allRegionSeText = string.Format("<!-- Start Region: {{title: \"All Region\", allowedComponentTypes: [{0}], minOccurs: 1, maxOccurs: 5 }} -->", string.Join(",", contentTypeJson.ToArray()));
// Push to the package to use in DWT..
package.PushItem("ALL_REGION", package.CreateStringItem(ContentType.Text, allRegionSeText));
Hope this helps.
Have you tried creating a region without specifying CT/Schema pairs? I remember seeing in an early implementation that you could drop a content type anywhere because regions hadn't been configured properly (or perhaps at all).

Tridion 2011 Sp1 allow to publish revision version of the component to staging target

Here is a scenario: I have a Page which have Component A. Component A have few linked components B and C. If Editor modifies component B and want to publish to staging target while component still in the workflow so Reviewer can view the changes on staging server before approve component B. When editor preview component he can see the changes, but when he publish to staging target it will grab the last checked in version of the Component A, which still linked to the unmodified version of Component B. How to pragmatically overwrite the default behavior to allow Editor publish his changes to staging environment before completing activity for the item?
Also, when component B inserted directly on the second page I was able to publish from VBScript from workflow automated activity using the following:
Dim strItemURI
strItemURI = CurrentWorkItem.GetItem(2).ID
Dim oComp
Set oComp = TDSE.GetObject(strItemURI, 1)
Call oComp.Publish("tcm:0-13-65537", True, True, False)
Set oComp = Nothing
FinishActivity "Automatic Activity ""Publish to Staging"" Finished"
Do I need to write custom resolver to accomplish above scenario to allow modified version of linked components published to staging environment while in workflow?
Any idea or samples will be appreciated.
Thanks.
Updated:
I'm trying to create TBB, which will replace modified version of the item in the package. Any idea on this? Here is some code:
public void Transform(Engine engine, Package package)
{
try
{
_publicationID = engine.PublishingContext.ResolvedItem.Item.Id.PublicationId;
string stagingTarget = Settings.GetSetting("StagingTargetUri");
PublicationTarget target = new PublicationTarget(new TcmUri(stagingTarget), engine.GetSession());
if(engine.PublishingContext.ResolvedItem.PublicationTarget!=null){
if (stagingTarget.Contains(engine.PublishingContext.ResolvedItem.PublicationTarget.Id.ToString()))
{
foreach (Item item in package.GetAllByType(ContentType.Component))
{
VersionedItem versionedItem = (VersionedItem)engine.GetObject(item);
if (versionedItem.LockType.HasFlag(LockType.InWorkflow))
{
Component componentInWorkflow =
(Component)engine.GetObject(new TcmUri(versionedItem.Id.ItemId, versionedItem.Id.ItemType, versionedItem.Id.PublicationId, 0));
package.Remove(item);
Item mainComponent= package.CreateTridionItem(ContentType.Component,componentInWorkflow);
package.PushItem(mainComponent);
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
According to documentation:
You can publish an item in Workflow if it meets the minimum approval
status set for the Publishing Target. If the item is in Workflow and
does not meet the minimum approval status, the Content Manager
publishes the last checked-in version of the item.
This means that you need to:
Set the Minimum Approval Status on your Publication target as something like "Staging"
As a first step on your Workflow set the Approval Status for your component to "Staging"

How can I modify the Book Copy module in Drupal 6 to forward the user to a different starting tab once a copy is made?

Example call to copy a book using the Book Copy module in Drupal 6 (assuming a node exists with book id of 142):
www.examplesite.com/book_copy/copy/142
When the above site is called and node 142 is copied it then notifies the user that the book was copied, but starts the user out on the Outline tab for the book copy. I think it would be more intuitive to start the user out on the Edit tab for the book copy so the user can immediately start to edit the information for the book. The outline is less important than setting up the actual initial details for the book which are in the Edit tab.
Does anyone know how I could modify the module to forward the user to the Edit tab? I looked through the code and it's just not clicking. I'm having problems interpreting exactly how this Book Module is working under the hood. Any suggestions will be greatly appreciated. Thanks!
I have no experience with the book_copy module, but looking at the last lines of the book_copy_copy_book() function:
$book = node_load(array('nid' => $newbid));
$book->bookcopydata = array();
$book->bookcopydata['message'] = t('Successfully cloned "%message", now viewing copy.', array('%message' => $message));
if (_book_outline_access($book)) {
$book->bookcopydata['url'] = 'node/'. $newbid .'/outline';
}
else {
$book->bookcopydata['url'] = 'node/'. $newbid;
}
// The function signature is: hook_book_copy_goto_alter(&$data);
drupal_alter("book_copy_goto", $book);
drupal_set_message($book->bookcopydata['message']);
drupal_goto($book->bookcopydata['url']); // requires user has 'administer book outline' or can access personal books
the user would automatically end on the new book page if he did not have the 'administer book outlines' right. If you want the user to always end on the new book edit page, you could just replace the whole if
if (_book_outline_access($book)) { ... }
clause with the assignment from its else part with an adjusted url:
$book->bookcopydata['url'] = 'node/'. $newbid . '/edit';
However, changing a modules code directly is not recommended (update clashes), especially if the module provides a hook to achieve the change you need 'from outside'. So the 'right' way in your situation would be to implement the offered hook_book_copy_goto_alter(&$data) in a custom module in order to adjust the redirection URL to your liking:
function yourModule_book_copy_goto_alter(&$new_book) {
$new_book->bookcopydata['url'] = 'node/'. $new_book->nid . '/edit';
}

Resources