diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-16 23:06:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 23:06:37 +0300 |
commit | 500ac74562627643d4e8f5a4513fb7b1881272ce (patch) | |
tree | 7de5d41e097e0d1f66c319119c1bd580a4d634c2 /main/src/addins/MonoDevelop.PackageManagement | |
parent | 5ff1e3fcfd4d2c67da43973ea00ba7598c050f8a (diff) | |
parent | c5a1af7353be4633e9ca84d0a25b619c8d478ab1 (diff) |
Merge pull request #9555 from mono/fix1021581-focusable-nuget-tabs
[NuGet] Use a custom label to allow tab focus in package management
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; |