Zonble: In-Place User Phrase Guiding Tooltip

This commit is contained in:
ShikiSuen 2022-01-15 23:59:01 +08:00
parent 3b5f24f328
commit ea1f6d9a12
9 changed files with 419 additions and 214 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
//
// TooltipContainer.swift
//
// Copyright (c) 2021-2022 The vChewing Project.
// Copyright (c) 2011-2022 The OpenVanilla Project.
//
// Contributors:
// Weizhong Yang (@zonble) @ OpenVanilla
// Shiki Suen (@ShikiSuen) @ vChewing // Color tweaks only
//
// Based on the Syrup Project and the Formosana Library
// by Lukhnos Liu (@lukhnos).
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
import Cocoa
public class TooltipController: NSWindowController {
private let backgroundColor = NSColor.windowBackgroundColor
private var messageTextField: NSTextField
private var tooltip: String = "" {
didSet {
messageTextField.stringValue = tooltip
adjustSize()
}
}
public init() {
let contentRect = NSRect(x: 128.0, y: 128.0, width: 300.0, height: 20.0)
let styleMask: NSWindow.StyleMask = [.borderless, .nonactivatingPanel]
let panel = NSPanel(contentRect: contentRect, styleMask: styleMask, backing: .buffered, defer: false)
panel.level = NSWindow.Level(Int(kCGPopUpMenuWindowLevel) + 1)
panel.hasShadow = true
messageTextField = NSTextField()
messageTextField.isEditable = false
messageTextField.isSelectable = false
messageTextField.isBezeled = false
messageTextField.textColor = NSColor.textColor
messageTextField.drawsBackground = true
messageTextField.backgroundColor = backgroundColor
messageTextField.font = .systemFont(ofSize: NSFont.systemFontSize(for: .small))
panel.contentView?.addSubview(messageTextField)
super.init(window: panel)
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc(showTooltip:atPoint:)
public func show(tooltip: String, at point: NSPoint) {
self.tooltip = tooltip
window?.orderFront(nil)
set(windowLocation: point)
}
@objc
public func hide() {
window?.orderOut(nil)
}
private func set(windowLocation location: NSPoint) {
var newPoint = location
if location.y > 5 {
newPoint.y -= 5
}
window?.setFrameTopLeftPoint(newPoint)
}
private func adjustSize() {
let attrString = messageTextField.attributedStringValue;
var rect = attrString.boundingRect(with: NSSize(width: 1600.0, height: 1600.0), options: .usesLineFragmentOrigin)
rect.size.width += 10
messageTextField.frame = rect
window?.setFrame(rect, display: true)
}
}

View File

@ -25,3 +25,5 @@
"Please check the permission of at \"%@\"." = "Please check the permission of at \"%@\".";
"Edit Excluded Phrases" = "Edit Excluded Phrases";
"Use Half-Width Punctuations" = "Use Half-Width Punctuations";
"You are now selecting \"%@\". You can add a phrase with two or more characters." = "You are now selecting \"%@\". You can add a phrase with two or more characters.";
"You are now selecting \"%@\". Press enter to add a new phrase." = "You are now selecting \"%@\". Press enter to add a new phrase.";

View File

@ -25,3 +25,5 @@
"Please check the permission of at \"%@\"." = "请检查此处的存取权限:\"%@\".";
"Edit Excluded Phrases" = "编辑要滤除的语汇";
"Use Half-Width Punctuations" = "啟用半角標點輸出";
"You are now selecting \"%@\". You can add a phrase with two or more characters." = "您目前选择了「%@」。请选择至少两个字,才能将其加入自订语汇。";
"You are now selecting \"%@\". Press enter to add a new phrase." = "您目前选择了「%@」。按下 Enter 就可以加入到自订语汇中。";

View File

@ -25,3 +25,5 @@
"Please check the permission of at \"%@\"." = "請檢查此處的存取權限:\"%@\".";
"Edit Excluded Phrases" = "編輯要濾除的語彙";
"Use Half-Width Punctuations" = "啟用半形標點輸出";
"You are now selecting \"%@\". You can add a phrase with two or more characters." = "您目前選擇了「%@」。請選擇至少兩個字,才能將其加入自訂語彙。";
"You are now selecting \"%@\". Press enter to add a new phrase." = "您目前選擇了「%@」。按下 Enter 就可以加入到自訂語彙中。";

View File

@ -24,6 +24,7 @@
5BDF2D012791C03B00838ADB /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */; };
5BDF2D032791C71200838ADB /* NonModalAlertWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */; };
5BDF2D062791DFF200838ADB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDF2D052791DA6700838ADB /* AppDelegate.swift */; };
5BE798A42792E58A00337FF9 /* TooltipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BE798A32792E58A00337FF9 /* TooltipController.swift */; };
5BF4A6FE27844738007DC6E7 /* frmAboutWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 5BF4A6FC27844738007DC6E7 /* frmAboutWindow.m */; };
5BF4A70027844DC5007DC6E7 /* frmAboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5BF4A70227844DC5007DC6E7 /* frmAboutWindow.xib */; };
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A0421A615FEF3F50061ED63 /* FastLM.cpp */; };
@ -106,6 +107,7 @@
5BDF2D002791C03B00838ADB /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
5BDF2D022791C71200838ADB /* NonModalAlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonModalAlertWindowController.swift; sourceTree = "<group>"; };
5BDF2D052791DA6700838ADB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5BE798A32792E58A00337FF9 /* TooltipController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TooltipController.swift; sourceTree = "<group>"; };
5BF4A6FB27844738007DC6E7 /* frmAboutWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = frmAboutWindow.h; sourceTree = "<group>"; };
5BF4A6FC27844738007DC6E7 /* frmAboutWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = frmAboutWindow.m; sourceTree = "<group>"; };
5BF4A70327844DD0007DC6E7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/frmAboutWindow.xib; sourceTree = "<group>"; };
@ -253,6 +255,23 @@
path = LanguageModel;
sourceTree = "<group>";
};
5BE798A12792E50F00337FF9 /* UI */ = {
isa = PBXGroup;
children = (
5BE798A22792E51F00337FF9 /* TooltipUI */,
6A0D4ED815FC0DA600ABF4B3 /* CandidateUI */,
);
path = UI;
sourceTree = "<group>";
};
5BE798A22792E51F00337FF9 /* TooltipUI */ = {
isa = PBXGroup;
children = (
5BE798A32792E58A00337FF9 /* TooltipController.swift */,
);
path = TooltipUI;
sourceTree = "<group>";
};
6A0D4E9215FC0CFA00ABF4B3 = {
isa = PBXGroup;
children = (
@ -285,8 +304,8 @@
6A0D4EC215FC0D3C00ABF4B3 /* Source */ = {
isa = PBXGroup;
children = (
5BE798A12792E50F00337FF9 /* UI */,
5B58E87D278413E7003EA2AD /* MITLicense.txt */,
6A0D4ED815FC0DA600ABF4B3 /* CandidateUI */,
6A38BBDD15FC115800A8A51F /* Data */,
6A0D4F1215FC0EB100ABF4B3 /* Engine */,
6ACA41E715FC1D9000935EF6 /* Installer */,
@ -647,6 +666,7 @@
5BF4A6FE27844738007DC6E7 /* frmAboutWindow.m in Sources */,
5B5F4F972792A4EA00922DC2 /* UserPhrasesLM.cpp in Sources */,
5B5F4F8E27928F9300922DC2 /* vChewingLM.cpp in Sources */,
5BE798A42792E58A00337FF9 /* TooltipController.swift in Sources */,
5BDF2D062791DFF200838ADB /* AppDelegate.swift in Sources */,
5BC3EE1B278FC48C00F5E44C /* VerticalCandidateController.swift in Sources */,
5B42B64027876FDC00BB9B9F /* UserOverrideModel.cpp in Sources */,