Skip to content

Commit

Permalink
Allow file format exclude list to be specified when creating template
Browse files Browse the repository at this point in the history
When the Create Template menu is selected the template information
dialog that is displayed has a text box where the file exclusion
list can be entered. This information will be added to the
template.json file.
  • Loading branch information
mrward committed Dec 13, 2017
1 parent 787dd87 commit c18c755
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ partial class TemplateInformationDialog : Dialog
TemplateTextEntry displayNameTextEntry;
TemplateTextEntry categoryTextEntry;
TemplateTextEntry descriptionTextEntry;
TemplateTextEntry fileFormatExcludeTextEntry;
Button selectCategoryButton;
List<Label> allLabels = new List<Label> ();

Expand Down Expand Up @@ -83,6 +84,12 @@ void Build ()
GettextCatalog.GetString ("Defines where the project template will be displayed in the New Project dialog."));
allLabels.Add (categoryTextEntry.Label);

fileFormatExcludeTextEntry = CreateTemplateTextEntry (
mainVBox,
GettextCatalog.GetString ("File Format Exclude:"),
GettextCatalog.GetString ("A semi-colon separated list of files (e.g. 'info.plist;*.min.js') which will not be formatted when creating the project."));
allLabels.Add (fileFormatExcludeTextEntry.Label);

selectCategoryButton = new Button ();
selectCategoryButton.Label = "\u2026";
categoryTextEntry.HBox.PackStart (selectCategoryButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public TemplateInformationDialog (TemplateInformation viewModel)
shortNameTextEntry.TextEntry.Text = viewModel.ShortName;
categoryTextEntry.TextEntry.Text = viewModel.Category;
descriptionTextEntry.TextEntry.Text = viewModel.Description;
fileFormatExcludeTextEntry.TextEntry.Text = viewModel.FileFormatExclude;

authorTextEntry.TextEntry.Changed += AuthorTextEntryChanged;
defaultProjectNameTextEntry.TextEntry.Changed += DefaultProjectNameTextEntryChanged;
Expand All @@ -57,6 +58,7 @@ public TemplateInformationDialog (TemplateInformation viewModel)
shortNameTextEntry.TextEntry.Changed += ShortNameTextEntryChanged;
categoryTextEntry.TextEntry.Changed += CategoryTextEntryChanged;
descriptionTextEntry.TextEntry.Changed += DescriptionTextChanged;
fileFormatExcludeTextEntry.TextEntry.Changed += FileFormatExcludeTextChanged ;

selectCategoryButton.Clicked += SelectCategoryButtonClicked;
}
Expand Down Expand Up @@ -107,6 +109,11 @@ void DescriptionTextChanged (object sender, EventArgs e)
viewModel.Description = descriptionTextEntry.TextEntry.Text;
}

void FileFormatExcludeTextChanged (object sender, EventArgs e)
{
viewModel.FileFormatExclude = fileFormatExcludeTextEntry.TextEntry.Text;
}

void SelectCategoryButtonClicked (object sender, EventArgs e)
{
using (var dialog = new TemplateCategoriesDialog ()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ namespace MonoDevelop.Templating
{
static class FileFormattingExcludeTagProvider
{
public static readonly string MonoDevelopFileFormatExcludeTagName = "md-file-format-exclude";
public static readonly string VSMacFileFormatExcludeTagName = "vsmac-file-format-exclude";

public static readonly string[] TagNames = new string [] {
"md-file-format-exclude",
"vsmac-file-format-exclude"
MonoDevelopFileFormatExcludeTagName,
VSMacFileFormatExcludeTagName
};

public static readonly string DefaultTagName;

static FileFormattingExcludeTagProvider ()
{
DefaultTagName = GetDefaultTagName ();
}

static string GetDefaultTagName ()
{
if (TemplatingServices.IsVisualStudio ()) {
return VSMacFileFormatExcludeTagName;
}

return MonoDevelopFileFormatExcludeTagName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using MonoDevelop.Core;

namespace MonoDevelop.Templating
{
class TemplateCategoryTagNameProvider
Expand All @@ -48,10 +45,8 @@ static TemplateCategoryTagNameProvider ()

static string GetDefaultCategoryTagName ()
{
if (BrandingService.ApplicationName != null) {
if (BrandingService.ApplicationName.StartsWith ("Visual Studio", StringComparison.OrdinalIgnoreCase)) {
return VSMacCategoryTagName;
}
if (TemplatingServices.IsVisualStudio ()) {
return VSMacCategoryTagName;
}

return MonoDevelopCategoryTagName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public TemplateInformation (FilePath baseDirectory, IEnumerable<DotNetProject> p
public string CategoryTagName { get; set; }
public string Category { get; set; }
public string Description { get; set; }
public string FileFormatExclude { get; set; }
public string FileFormatExcludeTagName { get; set; }
public string[] ProjectFilePrimaryOutputs { get; set; }
public string[] ProjectGuids { get; set; }

Expand All @@ -81,6 +83,8 @@ void GenerateDefaults ()
Language = project.LanguageName;
ShortName = project.Name;
Description = string.Empty;
FileFormatExclude = string.Empty;
FileFormatExcludeTagName = FileFormattingExcludeTagProvider.DefaultTagName;

Category = "other/net/general";
CategoryTagName = TemplateCategoryTagNameProvider.DefaultCategoryTagName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ static string AddProjectInfo (TemplateInformation template, string json)
outputs.Add (pathProperty);
}

if (!string.IsNullOrEmpty (template.FileFormatExclude)) {
var tags = jsonObject ["tags"];
tags [template.FileFormatExcludeTagName] = template.FileFormatExclude;
}

return ToString (jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public static void LogInfo (string message)
TemplatingOutputPad.WriteText (message);
}

public static bool IsVisualStudio ()
{
if (BrandingService.ApplicationName != null) {
if (BrandingService.ApplicationName.StartsWith ("Visual Studio", StringComparison.OrdinalIgnoreCase)) {
return true;
}
}

return false;
}

static IEnumerable<TemplateCategoryViewModel> AppendCustomCategories (this IEnumerable<TemplateCategoryViewModel> categories)
{
if (!TemplateCreatorAddinXmlFile.IsModified) {
Expand Down

0 comments on commit c18c755

Please sign in to comment.