How to set the defaults for an NSFontPanel? - xcode

I'm setting up the preferences window for my cool app, which displays some text. In preferences I've set up a button that opens an NSFontPanel. My app stores the user's preferred text color and font, and always opens with those settings so that the user never has to see text displayed in a color or font they don't prefer.
The problem is, while my app is able to remember these preferences, the NSFontPanel has trouble. When I first open the font panel, the default values for all the fields are reset. After fiddling with them, closing the panel, and then reopening it, the correct values are retained. The problem only occurs when I first open the panel.
I don't understand why this is happening!
I've been careful to set the font and color for the panel when my app starts, as you can see from this snippet:
def show_entry_font_menu(sender)
font_manager = NSFontManager.sharedFontManager
color_panel = NSColorPanel.sharedColorPanel
font_manager.setDelegate self
color_panel.setDelegate self
font_manager.setSelectedFont(preferences.entry_font, isMultiple:false)
font_panel = font_manager.fontPanel(true)
font_panel.makeKeyAndOrderFront(sender)
attributes = preferences.entry_font_attributes
color = preferences.entry_font_color
font_manager.setSelectedAttributes(attributes, isMultiple:false)
color_panel.setColor(color) if preferences.entry_font_color
self.did_open_font_panel = true
end

There is an oddness in initializing the sharedFontPanel. If you set the font before creating it the first time, that works fine, but setting attributes does not.
What you have to do is makeKeyAndOrderFront first, and then set the attributes. Once the panel has been thus created the first time it will properly reflect setSelectedAttributes.
font_panel.makeKeyAndOrderFront(sender)
font_manager.setSelectedAttributes(attributes, isMultiple:false)

Related

Removing/hiding the toolbar tracking separator

I'm working on adding support in my app for full-height sidebars, as introduced in macOS 11.
The trick is, when the window tab bar is visible, I want to turn the full-height sidebar off. The two don't mix well when the sidebar content is different in each window, as it is in my app. See Xcode for an example of what I want to do (View > Show Window Tab Bar). See Preview for an example of what I want to avoid (open two multi-page PDFs and put them in a single tabbed window).
What's working:
I observe the window's tabbedWindows property, and toggle the fullSizeContentView flag in its styleMask accordingly. Thus the window's style updates as needed when I hide and show the tab bar.
What's not working: I need to have a sidebarTrackingSeparator item in my toolbar in order to have some items above the sidebar. But when fullSizeContentView is off, that item appears as a plain separator. I don't want it to be visible at all in that state.
There isn't a straightforward way to hide a toolbar item, especially if it doesn't have a view, which it turns out this one doesn't.
I tried removing the separator item and re-adding it when the window state toggles, but that leads to Cocoa throwing exceptions, complaining that only one tracking item can be registered at a time. This would seem to be a bug, but Xcode manages it somehow.
So how can I properly toggle my window and toolbar state without having that visible separator?
It looks like I've solved the problem by saving the separator item when I see it in toolbarWillAddItem, and then returning it from toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:) to avoid having a new instance created. That way, removing and re-adding the item works without having exceptions thrown.
The last little snag was to not remove and re-add the separator blindly. The window state may have been preserved across app launches, so I needed to not make assumptions about how the window would initially appear.

Can I set tab text color or icon to indicate validation errors on the page in Xamarin TabbedPage (iOS and Android)?

I want users entering data across multiple tabs to be able to see at a glance whether and where they have validation errors / fields not populated. I can indicate errors for the selected form in the form body, but for unselected tabs I want to use red color and/or a red icon in the tab to indicate if it is failing validation.
I see various posts explaining how to use a custom renderer or effect to set tab text color for all tabs or selected/unselected tabs (e.g. here, here, here modifying the framework itself and here). However, the posts I've seen do not show a way to change the color of a SPECIFIC tab. In this case I want to either change the color or add/remove an error icon that would show beside the Title in the tab header based on the validation results for the page accessed via the tab. Is that possible?
Update:
I also found this - seemed more promising because it does seem to change tabs based on their positions or title rather than just on whether they were selected or not, but it seems to be dependent on using bottom tabs, which I'm not doing.
I also have found this, and element.Children[i] does get me the ContentPage from which I can determine what color I want the tab's test to be, and it's possible that the tab variable that's returned by activity.ActionBar.GetTabAt(i) somehow gives me access to update the tab's text color, but I'm not seeing any method or property that seems promising - basically I still don't see how to get access to the UITabBarItem so I can call SetTitleAndAttributes on it to set its text color. (Also, if I declare the tab variable by its type of Android.App.ActionBar.Tab instead of using var, I get a note saying that type has been deprecated. It seems upon investigation that the whole ActionBar class has been deprecated. But how can that be when it still exists as a property of Android.App.Activity, which is not deprecated?)
Many thanks for your assistance!

iText7 ViewerPreferences: Should display Bookmarks by default

I create a PDF with iText7, which should not show the toolbar. But it should display the area with the bookmarks/outlines.
PdfViewerPreferences pref = new PdfViewerPreferences();
pref.SetHideToolbar(true); // works
pref.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_OUTLINES); // doesn't work
pdfDocument.GetCatalog().SetViewerPreferences(pref);
Acrobat Reader should display it this way:
Documentation of SetNonFullScreenPageMode clearly says the following:
This entry is meaningful only if the value of the PageMode entry in the Catalog dictionary is FullScreen
Thus you need to also add the following line in order for your configuration to become active:
pdfDocument.GetCatalog().SetPageMode(PdfName.FullScreen);
However, this will make Acrobat ask you to enter full screen mode on opening the PDF and in full screen mode nothing is shown but the page content.
What you are really looking for is setting PageMode to UseOutlines:
pdfDocument.GetCatalog().SetPageMode(PdfName.UseOutlines);
Full code:
PdfViewerPreferences pref = new PdfViewerPreferences();
pref.SetHideToolbar(true);
pdfDocument.GetCatalog().SetViewerPreferences(pref);
pdfDocument.GetCatalog().SetPageMode(PdfName.UseOutlines);

"Always show selection" doesn't work on CListCtrl in list mode

I want a user to be able to select item(s) in my CListCtrl and then click on a button to act on those items. But when the focus is lost from the list, the selection is no longer shown, even if I set 'Always show selection' to true:
This happens both in the dialog test facility, and in my compiled application. I use list-mode, and have no icons, only text.
To reproduce:
Create a new dialog in the resource editor
Place a list-view control.
Set View = List in the properties
Set Always Show Selection = True in the properties
Add a button to the dialog
Press Ctrl-T to test the dialog
Select item(s) on the list, then press the button
..and the text is not visibly selected at all. Or is it... I can just
barely sort of see some very very faint selection in my screenshot - I
think. It's so faint I am not 100% certain it's there!
In addition to my comments: well, there you have it - they are selected, and in a different color, but it seems your screen settings are a bit off. Maybe your color settings, a high contrast mode, or the color setting for selected items in Windows.
The gray color in your screenshot is: #f7f3f7 - light gray, so you might have a problem seeing it, depending on the settings.
An interesting and very lightweight tool to check those things (zoom in, see the color values) is ZoomPlus. I use it every day, and there seems to be source code available too.

Hidden Window Display on Users Desktop

We have a VB6 application that uses a non-visible window (form) for DDE communication.
We have some clients reporting that occasionally they can see this window on their desktop.
I did a scan through the code for any visible = true or show's on the form in question, but nothing.
This about all we do with it:
Load frmDDELink
frmDDELink.stuff = stuff
We don't actually explicitly display (or explicitly not display it either).
What could cause a hidden window to be displayed on a user's desktop such that it is visible?
Try and set the location of the form to off-screen.
frmDDELink.ClientLeft = -100
frmDDELink.ClientTop = -100
A misbehaving app on the client's machine could do that. FindWindow() is a notoriously inaccurate API function. On top of that, all VB6 windows have the same class name. Thunder something, iirc. It might be finding your window instead of the one intended, making the wrong window visible.
I like Black Frog's simple hint to set the location off-screen, and nobugz's possible explanation. I would also suggest handling the Form_Activate event and setting the form invisible again.
Private Sub Form_Activate()
'Log something for debugging purposes?'
Me.Visible = False
End Sub
try to set the border into none, or me.visible = false, and set the property not to display in the task bar.

Resources