diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-16 13:37:50 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-16 20:06:02 +0300 |
commit | c5a1af7353be4633e9ca84d0a25b619c8d478ab1 (patch) | |
tree | 4b3a81d6341eca40f93e0802453c080d41af649c /main/src/addins/MonoDevelop.PackageManagement | |
parent | bfc78da3b0cd23288c809aaa522bf4ca3bd48886 (diff) |
[NuGet] Use a custom label to allow tab focus in package management
A regular label does not allow focus unless it's selectable or a link
and there is no simple workaround for that.
Fixes VSTS #1021581
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
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; |