forked from sillsdev/libpalaso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add inital Mac implementation of Usb + Keyboarding
These are not well tested. This version of MonoMac.dll includes additional methods for KeyboardInputSources and SelectedKeyboardInputSource for NSTextInputContext. chrisvire/monomac@b3cbfd2 mono/monomac#129
- Loading branch information
Showing
11 changed files
with
240 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#if __MonoCS__ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using MonoMac.Foundation; | ||
|
||
namespace Palaso.UsbDrive.Mac | ||
{ | ||
internal class UsbDriveInfoMac : UsbDriveInfo | ||
{ | ||
private static readonly NSString NSURLIsVolumeKey = new NSString("NSURLIsVolumeKey"); | ||
private static readonly NSString NSURLIsWritableKey = new NSString("NSURLIsWritableKey"); | ||
private static readonly NSString NSURLVolumeLocalizedNameKey = new NSString("NSURLVolumeLocalizedNameKey"); | ||
private static readonly NSString NSURLVolumeAvailableCapacityKey = new NSString("NSURLVolumeAvailableCapacityKey"); | ||
private static readonly NSString NSURLVolumeTotalCapacityKey = new NSString("NSURLVolumeTotalCapacityKey"); | ||
private static readonly NSString NSURLVolumeURLKey = new NSString("NSURLVolumeURLKey"); | ||
private static readonly NSString NSURLVolumeIsRemovableKey = new NSString("NSURLVolumeIsRemovableKey"); | ||
private static readonly NSString NSURLPathKey = new NSString("_NSURLPathKey"); | ||
|
||
private NSDictionary resourceValues; | ||
private NSUrl url; | ||
|
||
private UsbDriveInfoMac() | ||
{ | ||
} | ||
|
||
public override bool IsReady | ||
{ | ||
get { return true; } | ||
} | ||
|
||
public override DirectoryInfo RootDirectory | ||
{ | ||
get { return new DirectoryInfo(resourceValues[NSURLPathKey].ToString()); } | ||
} | ||
|
||
public override string VolumeLabel | ||
{ | ||
get { return resourceValues[NSURLVolumeLocalizedNameKey].ToString(); } | ||
} | ||
|
||
public override ulong TotalSize | ||
{ | ||
get { return (ulong) (NSNumber) resourceValues[NSURLVolumeTotalCapacityKey]; } | ||
} | ||
|
||
public override ulong AvailableFreeSpace | ||
{ | ||
get { return (ulong) (NSNumber) resourceValues[NSURLVolumeAvailableCapacityKey]; } | ||
} | ||
|
||
public new static List<IUsbDriveInfo> GetDrives() | ||
{ | ||
var drives = new List<IUsbDriveInfo>(); | ||
|
||
NSString[] keys = new NSString[] { | ||
NSURLIsVolumeKey, | ||
NSURLVolumeLocalizedNameKey, | ||
NSURLVolumeAvailableCapacityKey, | ||
NSURLVolumeTotalCapacityKey, | ||
NSURLVolumeIsRemovableKey, | ||
NSURLPathKey | ||
}; | ||
|
||
NSFileManager fm = NSFileManager.DefaultManager; | ||
var volumes = fm.GetMountedVolumes(NSArray.FromObjects(keys), NSVolumeEnumerationOptions.SkipHiddenVolumes); | ||
foreach (var url in volumes) | ||
{ | ||
NSError error; | ||
var values = url.GetResourceValues(keys, out error); | ||
if ((bool) (NSNumber) values[NSURLVolumeIsRemovableKey]) | ||
{ | ||
var driveInfo = new UsbDriveInfoMac(); | ||
driveInfo.resourceValues = values; | ||
driveInfo.url = url; | ||
drives.Add(driveInfo); | ||
} | ||
} | ||
|
||
return drives; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
103 changes: 103 additions & 0 deletions
103
PalasoUIWindowsForms/Keyboarding/Mac/MacKeyboardAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#if __MonoCS__ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows.Input; | ||
using MonoMac.Foundation; | ||
using Palaso.UI.WindowsForms.Keyboarding.Interfaces; | ||
using Palaso.UI.WindowsForms.Keyboarding.InternalInterfaces; | ||
using Palaso.WritingSystems; | ||
|
||
namespace Palaso.UI.WindowsForms.Keyboarding.Mac | ||
{ | ||
internal class MacKeyboardAdaptor : IKeyboardAdaptor | ||
{ | ||
protected List<IKeyboardErrorDescription> m_BadKeyboards; | ||
protected MonoMac.AppKit.NSTextInputContext m_Context; | ||
|
||
public MacKeyboardAdaptor() | ||
{ | ||
} | ||
|
||
protected void InitKeyboards() | ||
{ | ||
if (m_BadKeyboards != null) | ||
{ | ||
return; | ||
} | ||
|
||
ReinitKeyboards(); | ||
} | ||
|
||
private void ReinitKeyboards() | ||
{ | ||
m_BadKeyboards = new List<IKeyboardErrorDescription>(); | ||
m_Context = new MonoMac.AppKit.NSTextInputContext(); | ||
var sources = NSArray.FromArray<NSString>(m_Context.KeyboardInputSources); | ||
foreach (var source in sources.Select(kis => kis.ToString())) | ||
{ | ||
var localizedName = MonoMac.AppKit.NSTextInputContext.LocalizedNameForInputSource(source).ToString(); | ||
var keyboard = new MacKeyboardDescription(source, localizedName, this); | ||
KeyboardController.Manager.RegisterKeyboard(keyboard); | ||
} | ||
} | ||
public void Initialize() | ||
{ | ||
InitKeyboards(); | ||
} | ||
|
||
public void UpdateAvailableKeyboards() | ||
{ | ||
ReinitKeyboards(); | ||
} | ||
|
||
public void Close() | ||
{ | ||
m_Context = null; | ||
} | ||
|
||
public List<IKeyboardErrorDescription> ErrorKeyboards { get; private set; } | ||
public bool ActivateKeyboard(IKeyboardDefinition keyboard) | ||
{ | ||
Debug.Assert(keyboard is KeyboardDescription); | ||
Debug.Assert(((KeyboardDescription)keyboard).Engine == this); | ||
Debug.Assert(keyboard is MacKeyboardDescription); | ||
var cocoaKeyboard = keyboard as MacKeyboardDescription; | ||
m_Context.SelectedKeyboardInputSource = cocoaKeyboard.InputSource; | ||
|
||
return true; | ||
} | ||
|
||
public void DeactivateKeyboard(IKeyboardDefinition keyboard) | ||
{ | ||
} | ||
|
||
public IKeyboardDefinition GetKeyboardForInputLanguage(IInputLanguage inputLanguage) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IKeyboardDefinition CreateKeyboardDefinition(string layout, string locale) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IKeyboardDefinition ActiveKeyboard | ||
{ | ||
get | ||
{ | ||
var InputSource = m_Context.SelectedKeyboardInputSource; | ||
return Keyboard.Controller.AllAvailableKeyboards.OfType<MacKeyboardDescription>() | ||
.FirstOrDefault(macKeybd => macKeybd.InputSource == InputSource); | ||
} | ||
|
||
} | ||
|
||
public IKeyboardDefinition DefaultKeyboard { get; private set; } | ||
public KeyboardType Type { get { return KeyboardType.System;}} | ||
} | ||
} | ||
#endif | ||
|
23 changes: 23 additions & 0 deletions
23
PalasoUIWindowsForms/Keyboarding/Mac/MacKeyboardDescription.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if __MonoCS__ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Palaso.UI.WindowsForms.Keyboarding.InternalInterfaces; | ||
using Palaso.WritingSystems; | ||
|
||
namespace Palaso.UI.WindowsForms.Keyboarding.Mac | ||
{ | ||
internal class MacKeyboardDescription : KeyboardDescription | ||
{ | ||
internal MacKeyboardDescription(string source, string localizedName, IKeyboardAdaptor engine) : | ||
base(localizedName, source, String.Empty, null, engine) | ||
{ | ||
|
||
} | ||
|
||
public string InputSource { get { return Layout; } } | ||
} | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.