diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-16 23:06:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 23:06:30 +0300 |
commit | 38ec978b00d040eb6197f72e98e65226a521cb96 (patch) | |
tree | c88a279d3cf3e949c337f0f59e88d548448d0146 | |
parent | 1999799eef30e10aad66e0a00487897a99bcfba2 (diff) | |
parent | c37a4bce7ad53fa1ca170a082eba49a3e412a674 (diff) |
Merge pull request #9558 from mono/backport-pr-9555-to-release-8.4release-8.4-a11y
[release-8.4] [NuGet] Use a custom label to allow tab focus in package management
2 files changed, 68 insertions, 14 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.UI.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.UI.cs index f8e2435b85..5a23a14c4d 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.UI.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.UI.cs @@ -65,10 +65,10 @@ namespace MonoDevelop.PackageManagement ComboBox packageVersionComboBox; HBox packageVersionsHBox; Label packageVersionsLabel; - Label browseLabel; - Label installedLabel; - Label updatesLabel; - Label consolidateLabel; + CustomButtonLabel browseLabel; + CustomButtonLabel installedLabel; + CustomButtonLabel updatesLabel; + CustomButtonLabel consolidateLabel; HBox tabGroup; VBox projectsListViewVBox; Label projectsListViewLabel; @@ -114,33 +114,29 @@ namespace MonoDevelop.PackageManagement tabGroup = new HBox (); int tabLabelMinWidth = 60; - browseLabel = new Label (); + browseLabel = new CustomButtonLabel (); browseLabel.Text = GettextCatalog.GetString ("Browse"); browseLabel.Tag = browseLabel.Text; browseLabel.MinWidth = tabLabelMinWidth; browseLabel.MarginLeft = 10; - browseLabel.CanGetFocus = true; tabGroup.PackStart (browseLabel); - installedLabel = new Label (); + installedLabel = new CustomButtonLabel (); installedLabel.Text = GettextCatalog.GetString ("Installed"); installedLabel.Tag = installedLabel.Text; installedLabel.MinWidth = tabLabelMinWidth; - installedLabel.CanGetFocus = true; tabGroup.PackStart (installedLabel); - updatesLabel = new Label (); + updatesLabel = new CustomButtonLabel (); updatesLabel.Text = GettextCatalog.GetString ("Updates"); updatesLabel.Tag = updatesLabel.Text; updatesLabel.MinWidth = tabLabelMinWidth; - updatesLabel.CanGetFocus = true; tabGroup.PackStart (updatesLabel); - consolidateLabel = new Label (); + consolidateLabel = new CustomButtonLabel (); consolidateLabel.Text = GettextCatalog.GetString ("Consolidate"); consolidateLabel.Tag = consolidateLabel.Text; consolidateLabel.MinWidth = tabLabelMinWidth; - consolidateLabel.CanGetFocus = true; tabGroup.PackStart (consolidateLabel); topHBox.PackStart (tabGroup); @@ -506,5 +502,63 @@ namespace MonoDevelop.PackageManagement } } } + + sealed class CustomButtonLabel : Canvas + { + readonly TextLayout layout = new TextLayout (); + Size preferredSize; + + public string Text { + get { return layout.Text; } + set { + layout.Markup = null; + layout.Text = value; + Accessible.Title = layout.Text; + preferredSize = layout.GetSize (); + OnPreferredSizeChanged (); + } + } + + public string Markup { + get { return layout.Markup; } + set { + layout.Markup = value; + Accessible.Title = layout.Text; + preferredSize = layout.GetSize (); + OnPreferredSizeChanged (); + } + } + + public CustomButtonLabel () + { + CanGetFocus = true; + Accessible.Role = Xwt.Accessibility.Role.Button; + } + + protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint) + { + return preferredSize; + } + + protected override void OnDraw (Context ctx, Rectangle dirtyRect) + { + if (HasFocus) { + ctx.SetColor (Ide.Gui.Styles.BaseSelectionBackgroundColor); + } + var actualSize = Size; + var x = Math.Max (0, (actualSize.Width - preferredSize.Width) / 2); + var y = Math.Max (0, (actualSize.Height - preferredSize.Height) / 2); + x += x % 2; // align pixels + ctx.DrawTextLayout (layout, x, y); + } + + protected override void Dispose (bool disposing) + { + if (disposing) { + layout.Dispose (); + } + base.Dispose (disposing); + } + } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.cs index f4266e4ee3..b5b1fac718 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.cs @@ -1156,7 +1156,7 @@ namespace MonoDevelop.PackageManagement UpdatePackageResultsLabel (ManagePackagesPage.Consolidate, consolidateLabel); } - void UpdatePackageResultsLabel (ManagePackagesPage page, Label label) + void UpdatePackageResultsLabel (ManagePackagesPage page, CustomButtonLabel label) { string text = (string)label.Tag; if (page == viewModel.PageSelected) { @@ -1168,7 +1168,7 @@ namespace MonoDevelop.PackageManagement } } - static void UpdatePackageResultsLabelA11y (Label label, bool active) + static void UpdatePackageResultsLabelA11y (Widget label, bool active) { if (label.Surface.ToolkitEngine.Type == ToolkitType.Gtk) { var widget = label.Surface.NativeWidget as Gtk.Widget; |