* * *

Author Topic: macOS Extensions  (Read 262 times)

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1904
macOS Extensions
« on: April 15, 2018, 08:03:27 pm »
A little bit more of native macOS in LCL apps:
http://wiki.freepascal.org/macosext

ChrisR

  • Jr. Member
  • **
  • Posts: 53
Re: macOS Extensions
« Reply #1 on: April 24, 2018, 03:56:45 pm »
These features are really useful. Dark mode is great for radiology, I have employed your code into my Lazarus based MRI viewer
 https://github.com/neurolabusc/MRIcroGL/issues/20

I think this does a nice job of encapsulating useful MacOS features without interfering with the core LCL features and 'write once, compile everywhere' nature.

I do have two suggestions. I understand you are busy implementing core LCL Cocoa features, so these are low priority (want, not need). However, MacOS does provide two handy features that seem like a natural fit for your component:

1.) NSAlert is like a modal message, but it is attached to one specific form. This is great when you are using multiple applications, as it is obvious which form is the parent. A handy feature for your component would be to present a string of text for the user.

2.) NSUserNotification can be used for a lot of features. However, the easiest to implement for Lazrus, and a hugely influential role is to report a brief message that does not require any user intervention. This will tell the user something is happening, without requiring a modal response. For Lazarus, providing a string text message and a delay would be great.

Below are two XCode snippets to demonstrate these. These are both from my open source project
  https://github.com/neurolabusc/MRIcro
This is available in compiled form with MRIcroGL
  https://github.com/neurolabusc/MRIcroGL/releases

The NSAlert is shown when you File/Open an image and then press the 'i' button, the Notification is shown when a user has the "Only initial volumes" preference checked and they load a huge 4D dataset: in this case only the first 1 Gb of images are loaded, and the notification tells the user that they are only seeing part of the dataset (and how to remedy this).



- (IBAction)notifyNotAllVolumesLoaded: (int) loadedVols RawVols: (int) rawVols;
{
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    notification.title = [NSString stringWithFormat:@"Loaded %d of %d volumes", loadedVols, rawVols];
    notification.informativeText = @"Reason: The preference 'Only initial volumes' is selected";
    notification.soundName = NULL;
    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
    [NSTimer scheduledTimerWithTimeInterval: 4.5  target:self selector: @selector(closePopup) userInfo:self repeats:NO];
}

- (IBAction)infoClick:(id)sender { //
    NSString *message = [niiGL getHeaderInfo];
    NSBeginAlertSheet(@"Header Information", @"OK",NULL,NULL,theWindow, self,
                      NULL, NULL, NULL,
                      @"%@"
                      , message
                      );
}

ChrisR

  • Jr. Member
  • **
  • Posts: 53
Re: macOS Extensions
« Reply #2 on: April 24, 2018, 04:39:31 pm »
By the way, I note that there is other available code for NSUserNotification

  https://forum.lazarus.freepascal.org/index.php/topic,23977.15.html

To get the code to compile with Cocoa SVN 1.9, I needed to change the Uses, so "CarbonProc" becomes "CocoaUtils". I still think it might be nice to use your component as a wrapper for this function, to keep the Cocoa-specific features available.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus