📄 entry.tcl
字号:
# entry.tcl --## This file defines the default bindings for Tk entry widgets and provides# procedures that help in implementing those bindings.## RCS: @(#) $Id: entry.tcl,v 1.5 1998/09/14 18:23:23 stanton Exp $## Copyright (c) 1992-1994 The Regents of the University of California.# Copyright (c) 1994-1997 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.##-------------------------------------------------------------------------# Elements of tkPriv that are used in this file:## afterId - If non-null, it means that auto-scanning is underway# and it gives the "after" id for the next auto-scan# command to be executed.# mouseMoved - Non-zero means the mouse has moved a significant# amount since the button went down (so, for example,# start dragging out a selection).# pressX - X-coordinate at which the mouse button was pressed.# selectMode - The style of selection currently underway:# char, word, or line.# x, y - Last known mouse coordinates for scanning# and auto-scanning.#-------------------------------------------------------------------------#-------------------------------------------------------------------------# The code below creates the default class bindings for entries.#-------------------------------------------------------------------------bind Entry <<Cut>> { if {![catch {set data [string range [%W get] [%W index sel.first]\ [expr {[%W index sel.last] - 1}]]}]} { clipboard clear -displayof %W clipboard append -displayof %W $data %W delete sel.first sel.last }}bind Entry <<Copy>> { if {![catch {set data [string range [%W get] [%W index sel.first]\ [expr {[%W index sel.last] - 1}]]}]} { clipboard clear -displayof %W clipboard append -displayof %W $data }}bind Entry <<Paste>> { global tcl_platform catch { if {"$tcl_platform(platform)" != "unix"} { catch { %W delete sel.first sel.last } } %W insert insert [selection get -displayof %W -selection CLIPBOARD] tkEntrySeeInsert %W }}bind Entry <<Clear>> { %W delete sel.first sel.last}bind Entry <<PasteSelection>> { if {!$tkPriv(mouseMoved) || $tk_strictMotif} { tkEntryPaste %W %x }}# Standard Motif bindings:bind Entry <1> { tkEntryButton1 %W %x %W selection clear}bind Entry <B1-Motion> { set tkPriv(x) %x tkEntryMouseSelect %W %x}bind Entry <Double-1> { set tkPriv(selectMode) word tkEntryMouseSelect %W %x catch {%W icursor sel.first}}bind Entry <Triple-1> { set tkPriv(selectMode) line tkEntryMouseSelect %W %x %W icursor 0}bind Entry <Shift-1> { set tkPriv(selectMode) char %W selection adjust @%x}bind Entry <Double-Shift-1> { set tkPriv(selectMode) word tkEntryMouseSelect %W %x}bind Entry <Triple-Shift-1> { set tkPriv(selectMode) line tkEntryMouseSelect %W %x}bind Entry <B1-Leave> { set tkPriv(x) %x tkEntryAutoScan %W}bind Entry <B1-Enter> { tkCancelRepeat}bind Entry <ButtonRelease-1> { tkCancelRepeat}bind Entry <Control-1> { %W icursor @%x}bind Entry <Left> { tkEntrySetCursor %W [expr {[%W index insert] - 1}]}bind Entry <Right> { tkEntrySetCursor %W [expr {[%W index insert] + 1}]}bind Entry <Shift-Left> { tkEntryKeySelect %W [expr {[%W index insert] - 1}] tkEntrySeeInsert %W}bind Entry <Shift-Right> { tkEntryKeySelect %W [expr {[%W index insert] + 1}] tkEntrySeeInsert %W}bind Entry <Control-Left> { tkEntrySetCursor %W [tkEntryPreviousWord %W insert]}bind Entry <Control-Right> { tkEntrySetCursor %W [tkEntryNextWord %W insert]}bind Entry <Shift-Control-Left> { tkEntryKeySelect %W [tkEntryPreviousWord %W insert] tkEntrySeeInsert %W}bind Entry <Shift-Control-Right> { tkEntryKeySelect %W [tkEntryNextWord %W insert] tkEntrySeeInsert %W}bind Entry <Home> { tkEntrySetCursor %W 0}bind Entry <Shift-Home> { tkEntryKeySelect %W 0 tkEntrySeeInsert %W}bind Entry <End> { tkEntrySetCursor %W end}bind Entry <Shift-End> { tkEntryKeySelect %W end tkEntrySeeInsert %W}bind Entry <Delete> { if {[%W selection present]} { %W delete sel.first sel.last } else { %W delete insert }}bind Entry <BackSpace> { tkEntryBackspace %W}bind Entry <Control-space> { %W selection from insert}bind Entry <Select> { %W selection from insert}bind Entry <Control-Shift-space> { %W selection adjust insert}bind Entry <Shift-Select> { %W selection adjust insert}bind Entry <Control-slash> { %W selection range 0 end}bind Entry <Control-backslash> { %W selection clear}bind Entry <KeyPress> { tkEntryInsert %W %A}# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.# Otherwise, if a widget binding for one of these is defined, the# <KeyPress> class binding will also fire and insert the character,# which is wrong. Ditto for Escape, Return, and Tab.bind Entry <Alt-KeyPress> {# nothing}bind Entry <Meta-KeyPress> {# nothing}bind Entry <Control-KeyPress> {# nothing}bind Entry <Escape> {# nothing}bind Entry <Return> {# nothing}bind Entry <KP_Enter> {# nothing}bind Entry <Tab> {# nothing}if {$tcl_platform(platform) == "macintosh"} { bind Entry <Command-KeyPress> {# nothing}}# On Windows, paste is done using Shift-Insert. Shift-Insert already# generates the <<Paste>> event, so we don't need to do anything here.if {$tcl_platform(platform) != "windows"} { bind Entry <Insert> { catch {tkEntryInsert %W [selection get -displayof %W]} }}# Additional emacs-like bindings:bind Entry <Control-a> { if {!$tk_strictMotif} { tkEntrySetCursor %W 0 }}bind Entry <Control-b> { if {!$tk_strictMotif} { tkEntrySetCursor %W [expr {[%W index insert] - 1}] }}bind Entry <Control-d> { if {!$tk_strictMotif} { %W delete insert }}bind Entry <Control-e> { if {!$tk_strictMotif} { tkEntrySetCursor %W end }}bind Entry <Control-f> { if {!$tk_strictMotif} { tkEntrySetCursor %W [expr {[%W index insert] + 1}] }}bind Entry <Control-h> { if {!$tk_strictMotif} { tkEntryBackspace %W }}bind Entry <Control-k> { if {!$tk_strictMotif} { %W delete insert end }}bind Entry <Control-t> { if {!$tk_strictMotif} { tkEntryTranspose %W }}bind Entry <Meta-b> { if {!$tk_strictMotif} { tkEntrySetCursor %W [tkEntryPreviousWord %W insert] }}bind Entry <Meta-d> { if {!$tk_strictMotif} { %W delete insert [tkEntryNextWord %W insert] }}bind Entry <Meta-f> { if {!$tk_strictMotif} { tkEntrySetCursor %W [tkEntryNextWord %W insert] }}bind Entry <Meta-BackSpace> { if {!$tk_strictMotif} { %W delete [tkEntryPreviousWord %W insert] insert }}bind Entry <Meta-Delete> { if {!$tk_strictMotif} { %W delete [tkEntryPreviousWord %W insert] insert }}# A few additional bindings of my own.bind Entry <2> { if {!$tk_strictMotif} { %W scan mark %x set tkPriv(x) %x set tkPriv(y) %y set tkPriv(mouseMoved) 0 }}bind Entry <B2-Motion> { if {!$tk_strictMotif} { if {abs(%x-$tkPriv(x)) > 2} { set tkPriv(mouseMoved) 1 } %W scan dragto %x }}# tkEntryClosestGap --# Given x and y coordinates, this procedure finds the closest boundary# between characters to the given coordinates and returns the index# of the character just after the boundary.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -