Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit fcd3ab3

Browse files
sevokumonojenkins
authored andcommitted
[Ide] Separate template name and category in the new project dialog model
Previously we have been using the same tree model column for the template name and category, depending on the purpose. Since our UI tests rely on the template name to be set in this column, with this change we do a clear separation between those.
1 parent c5be897 commit fcd3ab3

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.UI.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,18 @@ partial class GtkNewProjectDialogBackend : IdeDialog
5858
TreeStore templateCategoriesTreeStore =
5959
new TreeStore(typeof (string), typeof (Xwt.Drawing.Image), typeof(TemplateCategory));
6060
TreeView templatesTreeView;
61+
// DO NOT REMOVE
62+
// This column is not used here, but is required for
63+
// external UI tests which need a plain string name inside the model
64+
// This is a reminder to not remove or abuse this column for other purposes
65+
const int TemplateNameColumn = 0;
66+
// DO NOT REMOVE
6167
const int TemplateIconColumn = 1;
6268
const int TemplateColumn = 2;
63-
const int TemplateA11yLanguageName = 3;
69+
const int TemplateOwnCategoryNameColumn = 3;
70+
const int TemplateA11yLanguageNameColumn = 4;
6471
TreeStore templatesTreeStore =
65-
new TreeStore(typeof (string), typeof (Xwt.Drawing.Image), typeof(SolutionTemplate), typeof (string));
72+
new TreeStore(typeof (string), typeof (Xwt.Drawing.Image), typeof(SolutionTemplate), typeof (string), typeof (string));
6673
VBox templateVBox;
6774
ImageView templateImage;
6875
Label templateNameLabel;

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkNewProjectDialogBackend.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public GtkNewProjectDialogBackend ()
5454
// Set up the list store so the test framework can work out the correct columns
5555
SemanticModelAttribute modelAttr = new SemanticModelAttribute ("templateCategoriesListStore__Name", "templateCategoriesListStore__Icon", "templateCategoriesListStore__Category");
5656
TypeDescriptor.AddAttributes (templateCategoriesTreeStore, modelAttr);
57-
modelAttr = new SemanticModelAttribute ("templateListStore__Name", "templateListStore__Icon", "templateListStore__Template");
57+
modelAttr = new SemanticModelAttribute ("templateListStore__Name", "templateListStore__Icon", "templateListStore__Template", "templateListStore__Category", "templateListStore__Language");
5858
TypeDescriptor.AddAttributes (templatesTreeStore, modelAttr);
5959

6060
templateCategoriesTreeView.Selection.Changed += TemplateCategoriesTreeViewSelectionChanged;
@@ -138,13 +138,13 @@ static void SetTemplateTextCellData (TreeViewColumn col, CellRenderer renderer,
138138
var templateTextRenderer = (GtkTemplateCellRenderer)renderer;
139139
templateTextRenderer.Template = template;
140140
templateTextRenderer.TemplateIcon = model.GetValue (it, TemplateIconColumn) as Xwt.Drawing.Image;
141-
templateTextRenderer.TemplateCategory = model.GetValue (it, TemplateCategoryNameColumn) as string;
141+
templateTextRenderer.TemplateCategory = model.GetValue (it, TemplateOwnCategoryNameColumn) as string;
142142
}
143143

144144
static void SetLanguageCellData (TreeViewColumn col, CellRenderer renderer, TreeModel model, TreeIter it)
145145
{
146146
var template = (SolutionTemplate)model.GetValue (it, TemplateColumn);
147-
var language = (string)model.GetValue (it, TemplateA11yLanguageName);
147+
var language = (string)model.GetValue (it, TemplateA11yLanguageNameColumn);
148148
var languageRenderer = (LanguageCellRenderer)renderer;
149149
languageRenderer.Template = template;
150150
languageRenderer.SelectedLanguage = language ?? template?.Language ?? string.Empty;
@@ -231,7 +231,7 @@ void AddLanguageMenuItems (Xwt.Menu menu, SolutionTemplate template)
231231
controller.SelectedLanguage = language;
232232
templatesTreeView.QueueDraw ();
233233
if (templatesTreeView.Selection.GetSelected (out var selIter))
234-
templatesTreeStore.SetValue (selIter, TemplateA11yLanguageName, languageCellRenderer.SelectedLanguage);
234+
templatesTreeStore.SetValue (selIter, TemplateA11yLanguageNameColumn, languageCellRenderer.SelectedLanguage);
235235
ShowSelectedTemplate ();
236236
};
237237
menu.Items.Add (menuItem);
@@ -394,19 +394,21 @@ void ShowTemplatesForCategory (TemplateCategory category)
394394
languageCellRenderer.RenderRecentTemplate = false;
395395
foreach (TemplateCategory subCategory in category.Categories) {
396396
var iter = templatesTreeStore.AppendValues (
397-
MarkupTopLevelCategoryName (subCategory.Name),
397+
subCategory.Name,
398398
null,
399399
null,
400+
subCategory.Name,
400401
null);
401402

402403
foreach (SolutionTemplate template in subCategory.Templates) {
403404
if (template.HasProjects || controller.IsNewSolution) {
404405
string language = GetLanguageForTemplate (template);
405406
templatesTreeStore.AppendValues (
406407
iter,
407-
subCategory.Name,
408+
template.Name,
408409
GetIcon (template.IconId, IconSize.Dnd),
409410
template,
411+
subCategory.Name,
410412
language);
411413
}
412414
}
@@ -427,19 +429,22 @@ string GetLanguageForTemplate (SolutionTemplate template)
427429
void ShowRecentTemplates ()
428430
{
429431
templateTextRenderer.RenderRecentTemplate = true;
430-
languageCellRenderer.RenderRecentTemplate = true;
432+
languageCellRenderer.RenderRecentTemplate = true;
433+
var subCategoryName = Core.GettextCatalog.GetString ("Recently used templates");
431434
var iter = templatesTreeStore.AppendValues (
432-
MarkupTopLevelCategoryName (Core.GettextCatalog.GetString ("Recently used templates")),
435+
subCategoryName,
433436
null,
434437
null,
438+
subCategoryName,
435439
null);
436440
foreach (SolutionTemplate template in controller.RecentTemplates) {
437441
if (template.HasProjects || controller.IsNewSolution) {
438442
templatesTreeStore.AppendValues (
439443
iter,
440-
controller.GetCategoryPathText (template),
444+
template.Name,
441445
GetIcon (template.IconId, IconSize.Dnd),
442446
template,
447+
controller.GetCategoryPathText (template),
443448
template.Language);
444449
}
445450
}
@@ -483,7 +488,7 @@ void ShowTemplate (SolutionTemplate template)
483488

484489
TreeIter item;
485490
if (templatesTreeView.Selection.GetSelected (out item)) {
486-
templatesTreeStore.SetValue (item, TemplateA11yLanguageName, language);
491+
templatesTreeStore.SetValue (item, TemplateA11yLanguageNameColumn, language);
487492
}
488493

489494
templateNameLabel.Markup = MarkupTemplateName (template.Name);

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/GtkTemplateCellRenderer.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public string TemplateCategory {
7373

7474
void SetAccessibilityText ()
7575
{
76-
if (template != null) {
77-
var text = template.Name;
78-
if (!string.IsNullOrEmpty (templateCategory))
79-
text += ", " + templateCategory.Replace ("→", "–"); // we don't want narrators to read "right arrow"
80-
Text = text;
76+
Text = template?.Name ?? string.Empty;
77+
if (!string.IsNullOrEmpty (templateCategory)) {
78+
if (!string.IsNullOrEmpty (Text))
79+
Text += ", ";
80+
Text += templateCategory.Replace ("→", "–"); // we don't want narrators to read "right arrow"
8181
}
8282
}
8383

@@ -133,7 +133,7 @@ void DrawTemplateCategoryText (Drawable window, Widget widget, Rectangle cell_ar
133133
int textPixelWidth = widget.Allocation.Width - ((int)Xpad * 2);
134134
layout.Width = (int)(textPixelWidth * Pango.Scale.PangoScale);
135135

136-
layout.SetMarkup (TemplateCategory);
136+
layout.SetMarkup (MarkupTopLevelCategoryName (TemplateCategory));
137137

138138
int w, h;
139139
layout.GetPixelSize (out w, out h);
@@ -213,6 +213,11 @@ static StateType GetState (Widget widget, CellRendererState flags)
213213
stateType = widget.HasFocus ? StateType.Selected : StateType.Active;
214214
return stateType;
215215
}
216+
217+
static string MarkupTopLevelCategoryName (string name)
218+
{
219+
return "<span font_weight='bold'>" + GLib.Markup.EscapeText (name) + "</span>";
220+
}
216221
}
217222
}
218223

0 commit comments

Comments
 (0)