From: Po Lu Date: Wed, 11 May 2022 02:02:21 +0000 (+0000) Subject: Try to preserve font styles in the Haiku font dialog X-Git-Tag: emacs-29.0.90~1910^2~823 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=736081320803c6d1f987f753f63581a0fd42b1fe;p=emacs.git Try to preserve font styles in the Haiku font dialog * haiku_support.cc (class EmacsFontSelectionDialog) (UpdateStylesForIndex): If a style was previously selected and exists in the new family as well, select it after adding the new items. --- diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 6b4951e139a..cb9dfabc4e7 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2619,13 +2619,22 @@ class EmacsFontSelectionDialog : public BWindow void UpdateStylesForIndex (int idx) { - int n, i; + int n, i, previous_selection; uint32 flags; font_family family; font_style style; BStringItem *item; + char *current_style; n = all_styles.CountItems (); + current_style = NULL; + previous_selection = font_style_pane.CurrentSelection (); + + if (previous_selection >= 0) + { + item = all_styles.ItemAt (previous_selection); + current_style = strdup (item->Text ()); + } font_style_pane.MakeEmpty (); all_styles.MakeEmpty (); @@ -2641,6 +2650,10 @@ class EmacsFontSelectionDialog : public BWindow else item = new BStringItem (""); + if (current_style && pending_selection_idx < 0 + && !strcmp (current_style, style)) + pending_selection_idx = i; + font_style_pane.AddItem (item); all_styles.AddItem (item); } @@ -2654,6 +2667,9 @@ class EmacsFontSelectionDialog : public BWindow pending_selection_idx = -1; UpdateForSelectedStyle (); + + if (current_style) + free (current_style); } bool