Skip to content

Commit

Permalink
Forbidding activating automatic session when output is in client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranganath Atreya committed Sep 15, 2019
1 parent d4e860c commit 509e845
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 25 deletions.
42 changes: 29 additions & 13 deletions Application/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -711,7 +712,7 @@
</connections>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="X93-6e-NOV">
<rect key="frame" x="509" y="13" width="82" height="32"/>
<rect key="frame" x="415" y="13" width="82" height="32"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="70" id="Ceg-Cs-v40"/>
</constraints>
Expand Down Expand Up @@ -752,7 +753,7 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="M8k-vC-hCq">
<rect key="frame" x="591" y="13" width="82" height="32"/>
<rect key="frame" x="497" y="13" width="82" height="32"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="70" id="PxU-7E-OaK"/>
</constraints>
Expand All @@ -772,6 +773,19 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PGN-tv-JsE">
<rect key="frame" x="579" y="13" width="91" height="32"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="70" id="fwC-Bd-PHx"/>
</constraints>
<buttonCell key="cell" type="push" title="Defaults" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="jgg-su-EVJ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="defaultPressed:" target="U0M-Ta-Tra" id="ppV-Nd-EyK"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="iAz-Uu-qoW" secondAttribute="trailing" constant="20" symbolic="YES" id="0Fl-hk-3H6"/>
Expand All @@ -781,6 +795,8 @@
<constraint firstItem="CYo-m2-sV6" firstAttribute="centerY" secondItem="zlT-GH-SxP" secondAttribute="centerY" id="4T1-Hm-YnD"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="CYo-m2-sV6" secondAttribute="trailing" constant="20" symbolic="YES" id="85p-v9-F1i"/>
<constraint firstItem="Nku-MZ-A3h" firstAttribute="centerY" secondItem="3W1-2d-fZz" secondAttribute="centerY" id="8hH-mg-zKT"/>
<constraint firstItem="PGN-tv-JsE" firstAttribute="baseline" secondItem="M8k-vC-hCq" secondAttribute="baseline" id="8xx-h3-zAN"/>
<constraint firstItem="PGN-tv-JsE" firstAttribute="trailing" secondItem="CYo-m2-sV6" secondAttribute="trailing" id="9Wf-we-xJA"/>
<constraint firstItem="bRM-oq-5I0" firstAttribute="leading" secondItem="XQJ-nw-rve" secondAttribute="leading" constant="20" symbolic="YES" id="B2e-dz-Igg"/>
<constraint firstItem="N72-27-Z1w" firstAttribute="leading" secondItem="XQJ-nw-rve" secondAttribute="leading" constant="20" symbolic="YES" id="Gru-ng-f0z"/>
<constraint firstItem="eZp-jT-bzR" firstAttribute="centerY" secondItem="bRM-oq-5I0" secondAttribute="centerY" id="I2x-k2-KFe"/>
Expand Down Expand Up @@ -811,7 +827,6 @@
<constraint firstItem="Rbi-WB-b4W" firstAttribute="leading" secondItem="XQJ-nw-rve" secondAttribute="leading" constant="20" symbolic="YES" id="eVo-wf-kvE"/>
<constraint firstItem="eZp-jT-bzR" firstAttribute="leading" secondItem="bRM-oq-5I0" secondAttribute="trailing" constant="8" symbolic="YES" id="eaz-lQ-e3G"/>
<constraint firstItem="Nku-MZ-A3h" firstAttribute="leading" secondItem="3W1-2d-fZz" secondAttribute="trailing" constant="8" symbolic="YES" id="ecc-ot-CLl"/>
<constraint firstAttribute="trailing" secondItem="M8k-vC-hCq" secondAttribute="trailing" constant="20" symbolic="YES" id="f2Y-4A-J7o"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="VAn-tM-lj4" secondAttribute="trailing" constant="20" symbolic="YES" id="gKD-Ho-5wT"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Bqd-ab-6zI" secondAttribute="trailing" constant="20" symbolic="YES" id="ggm-ci-tdW"/>
<constraint firstItem="X93-6e-NOV" firstAttribute="top" secondItem="iAz-Uu-qoW" secondAttribute="bottom" constant="25" id="hCk-qN-H8t"/>
Expand All @@ -827,6 +842,7 @@
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="N72-27-Z1w" secondAttribute="trailing" constant="20" symbolic="YES" id="nw4-kb-UZa"/>
<constraint firstItem="8pg-Jq-kba" firstAttribute="centerY" secondItem="zlT-GH-SxP" secondAttribute="centerY" id="o34-SN-7jA"/>
<constraint firstItem="Tou-TA-t3C" firstAttribute="centerY" secondItem="DAa-mK-H52" secondAttribute="centerY" id="o3Q-EG-x1J"/>
<constraint firstItem="PGN-tv-JsE" firstAttribute="leading" secondItem="M8k-vC-hCq" secondAttribute="trailing" constant="12" symbolic="YES" id="pfB-1o-0da"/>
<constraint firstItem="9bx-hV-rCB" firstAttribute="leading" secondItem="Epu-Zl-pT3" secondAttribute="trailing" constant="8" symbolic="YES" id="pzo-LJ-9EX"/>
<constraint firstAttribute="bottom" secondItem="X93-6e-NOV" secondAttribute="bottom" constant="20" symbolic="YES" id="uwA-uJ-h3h"/>
<constraint firstItem="DAa-mK-H52" firstAttribute="top" secondItem="zlT-GH-SxP" secondAttribute="bottom" constant="18" id="vj3-hy-k2k"/>
Expand Down Expand Up @@ -886,15 +902,15 @@
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W1F-KT-6vH">
<rect key="frame" x="20" y="20" width="300" height="250"/>
<clipView key="contentView" drawsBackground="NO" id="cT2-AL-61y">
<rect key="frame" x="1" y="1" width="283" height="248"/>
<rect key="frame" x="1" y="1" width="298" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="lhz-iO-l9e">
<rect key="frame" x="0.0" y="0.0" width="283" height="248"/>
<rect key="frame" x="0.0" y="0.0" width="298" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="283" height="248"/>
<size key="minSize" width="298" height="248"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
<connections>
Expand All @@ -912,7 +928,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="KZn-Wg-RZV">
<rect key="frame" x="284" y="1" width="15" height="248"/>
<rect key="frame" x="283" y="1" width="16" height="248"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down Expand Up @@ -940,15 +956,15 @@
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tap-rg-zxW">
<rect key="frame" x="20" y="20" width="300" height="250"/>
<clipView key="contentView" drawsBackground="NO" id="5fF-mu-NWr">
<rect key="frame" x="1" y="1" width="283" height="248"/>
<rect key="frame" x="1" y="1" width="298" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="XjA-1F-Rbi">
<rect key="frame" x="0.0" y="-1" width="283" height="248"/>
<rect key="frame" x="0.0" y="-1" width="298" height="248"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="283" height="248"/>
<size key="minSize" width="298" height="248"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
<connections>
Expand All @@ -966,7 +982,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="rI2-rQ-rZt">
<rect key="frame" x="284" y="1" width="15" height="248"/>
<rect key="frame" x="283" y="1" width="16" height="248"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
Expand Down
21 changes: 19 additions & 2 deletions Application/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate {
let factory = try! LiteratorFactory(config: config)
schemeName.addItems(withTitles: try! factory.availableSchemes())
schemeName.selectItem(withTitle: config.schemeName)
logLevel.addItems(withTitles: [Level.debug.rawValue, Level.warning.rawValue, Level.error.rawValue, Level.fatal.rawValue])
logLevel.addItems(withTitles: [Logger.Level.debug.rawValue, Logger.Level.warning.rawValue, Logger.Level.error.rawValue, Logger.Level.fatal.rawValue])
logLevel.selectItem(withTitle: config.logLevel.rawValue)
stopCharacter.stringValue = String(config.stopCharacter)
escapeCharacter.stringValue = String(config.escapeCharacter)
Expand All @@ -44,13 +44,24 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate {
stopCharacter.backgroundColor = NSColor.white
saveButton.title = "Save"
saveButton.isEnabled = false
outputInClientSideEffects()
}

private func isValid() -> Bool {
return stopCharacter.stringValue.unicodeScalars.count == 1
&& escapeCharacter.stringValue.unicodeScalars.count == 1
}

private func outputInClientSideEffects() {
let isOutputInClient = outputInClient.selectedTag() == 1
activeSessionOnDelete.state = isOutputInClient ? .off : (config.activeSessionOnDelete ? .on : .off)
activeSessionOnInsert.state = isOutputInClient ? .off : (config.activeSessionOnInsert ? .on : .off)
activeSessionOnCursorMove.state = isOutputInClient ? .off : (config.activeSessionOnCursorMove ? .on : .off)
activeSessionOnDelete.isEnabled = !isOutputInClient
activeSessionOnInsert.isEnabled = !isOutputInClient
activeSessionOnCursorMove.isEnabled = !isOutputInClient
}

private func makeSaveable() {
if !isValid() {
saveButton.title = "Invalid!"
Expand Down Expand Up @@ -83,6 +94,7 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate {
}

@IBAction func outputInClientChanged(_ sender: NSButton) {
outputInClientSideEffects()
makeSaveable()
}

Expand All @@ -106,9 +118,14 @@ class SettingsViewController: NSViewController, NSTextFieldDelegate {
reset()
}

@IBAction func defaultPressed(_ sender: NSButton) {
config.reset()
reset()
}

@IBAction func savePressed(_ sender: NSButton) {
config.schemeName = schemeName.titleOfSelectedItem!
config.logLevel = Level(rawValue: logLevel.titleOfSelectedItem!)!
config.logLevel = Logger.Level(rawValue: logLevel.titleOfSelectedItem!)!
config.stopCharacter = stopCharacter.stringValue.unicodeScalars.first!
config.escapeCharacter = escapeCharacter.stringValue.unicodeScalars.first!
config.showCandidates = showCandidates.state == .on
Expand Down
26 changes: 18 additions & 8 deletions Input Source/LipikaConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import Foundation
import LipikaEngine_OSX

class LipikaConfig: Config {
private static let kGroupDomainName = "group.daivajnanam.Lipika"
private let userDefaults: UserDefaults

func reset() {
UserDefaults.standard.removePersistentDomain(forName: LipikaConfig.kGroupDomainName)
UserDefaults.standard.synchronize()
}

override init() {
guard let groupDefaults = UserDefaults(suiteName: "group.daivajnanam.Lipika") else {
fatalError("Unable to open UserDefaults for suite: group.daivajnanam.Lipika!")
guard let groupDefaults = UserDefaults(suiteName: LipikaConfig.kGroupDomainName) else {
fatalError("Unable to open UserDefaults for suite: \(LipikaConfig.kGroupDomainName)!")
}
self.userDefaults = groupDefaults
super.init()
Expand All @@ -39,10 +45,10 @@ class LipikaConfig: Config {
}
}

override var logLevel: Level {
override var logLevel: Logger.Level {
get {
if let logLevelString = userDefaults.string(forKey: #function) {
return Level.init(rawValue: logLevelString)!
return Logger.Level(rawValue: logLevelString)!
}
else {
return super.logLevel
Expand Down Expand Up @@ -122,10 +128,14 @@ class LipikaConfig: Config {
userDefaults.set(value, forKey: #function)
}
}


/*
It is impossible to reliably determine the PositionalUnit a give client uses to report caret location.
And so, when output is in client, don't try to start your own session.
*/
var activeSessionOnDelete: Bool {
get {
return userDefaults.bool(forKey: #function)
return !outputInClient && userDefaults.bool(forKey: #function)
}
set(value) {
userDefaults.set(value, forKey: #function)
Expand All @@ -134,7 +144,7 @@ class LipikaConfig: Config {

var activeSessionOnInsert: Bool {
get {
return userDefaults.bool(forKey: #function)
return !outputInClient && userDefaults.bool(forKey: #function)
}
set(value) {
userDefaults.set(value, forKey: #function)
Expand All @@ -143,7 +153,7 @@ class LipikaConfig: Config {

var activeSessionOnCursorMove: Bool {
get {
return userDefaults.bool(forKey: #function)
return !outputInClient && userDefaults.bool(forKey: #function)
}
set(value) {
userDefaults.set(value, forKey: #function)
Expand Down
4 changes: 2 additions & 2 deletions Input Source/LipikaController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class LipikaController: IMKInputController {
if transliterator.isEmpty() {
Logger.log.debug("Transliterator is empty, not handling cursor move")
}
else if clientManager.updateMarkedCursorLocation(delta) {
else if !config.outputInClient, clientManager.updateMarkedCursorLocation(delta) {
showActive(transliterator.transliterate())
return true
}
Expand All @@ -91,7 +91,7 @@ public class LipikaController: IMKInputController {
return
}
// Calculate the location of cursor within Marked Text
self.clientManager.markedCursorLocation = config.outputInClient ? location - actual.location : transliterator.findPosition(forPosition: location - actual.location, inOutput: true)
self.clientManager.markedCursorLocation = config.outputInClient ? location - actual.location : transliterator.convertPosition(position: location - actual.location, fromUnits: .outputScalar, toUnits: .input)
Logger.log.debug("Marked Cursor Location: \(self.clientManager.markedCursorLocation!) for Global Location: \(location - actual.location)")
self.showActive(literated, replacementRange: actual)
}
Expand Down

0 comments on commit 509e845

Please sign in to comment.