Compare commits
6 Commits
dee9141e91
...
c4923c5871
| Author | SHA1 | Date | |
|---|---|---|---|
| c4923c5871 | |||
| c2d128dd42 | |||
| 166cd5f4d8 | |||
| 782ed0298a | |||
| 3de27dac4f | |||
| 1c7c2ec90e |
8
debian/changelog
vendored
8
debian/changelog
vendored
@@ -1,3 +1,10 @@
|
||||
projman (2.0.0-beta3) stable; urgency=medium
|
||||
|
||||
* Вынес код связанный с обработкой подсказок при вводе переменных и процедур в отдельный модуль.
|
||||
* Исправил работу со списком переменных из всплывающего окна. Теперь там можно выбрать из списка стрелками и вставить по Enter. Исправил обработку клавиш Вверх Вниз Ввод Отмена в окне со списком вариантов.
|
||||
|
||||
-- svk <svk@nuk-svk.ru> Thu, 29 Jan 2026 14:22:55 +0300
|
||||
|
||||
projman (2.0.0-beta2) stable; urgency=medium
|
||||
|
||||
* Добавлено подключение (bind) сочетания клавиш указанных в настройках инструментов.
|
||||
@@ -486,3 +493,4 @@ projman (2.0.0-alfa0) stable; urgency=medium
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
354
lib/editor.tcl
354
lib/editor.tcl
@@ -16,7 +16,7 @@ namespace eval Editor {
|
||||
$node.frmText.t configure -$optionName $value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Comment one string or selected string
|
||||
proc Comment {txt fileType} {
|
||||
global lexers cfgVariables
|
||||
@@ -402,236 +402,16 @@ namespace eval Editor {
|
||||
}
|
||||
|
||||
}
|
||||
proc VarHelperKey { widget K A } {
|
||||
set win .varhelper
|
||||
# if { [winfo exists $win] == 0 } { return }
|
||||
set ind [$win.lBox curselection]
|
||||
# puts ">>>>>>>>>>>> VarHelperBind <<<<<<<<<<<<<<<<"
|
||||
|
||||
switch -- $K {
|
||||
Prior {
|
||||
set up [expr [$win.lBox index active] - [$win.lBox cget -height]]
|
||||
if { $up < 0 } { set up 0 }
|
||||
$win.lBox activate $up
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $up $up
|
||||
}
|
||||
Next {
|
||||
set down [expr [$win.lBox index active] + [$win.lBox cget -height]]
|
||||
if { $down >= [$win.lBox index end] } { set down end }
|
||||
$win.lBox activate $down
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $down $down
|
||||
}
|
||||
Up {
|
||||
set up [expr [$win.lBox index active] - 1]
|
||||
if { $up < 0 } { set up 0 }
|
||||
$win.lBox activate $up
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $up $up
|
||||
}
|
||||
Down {
|
||||
set down [expr [$win.lBox index active] + 1]
|
||||
if { $down >= [$win.lBox index end] } { set down end }
|
||||
$win.lBox activate $down
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $down $down
|
||||
}
|
||||
Return {
|
||||
$widget delete "insert - 1 chars wordstart" "insert wordend - 1 chars"
|
||||
$widget insert "insert" [$win.lBox get [$win.lBox curselection]]
|
||||
# eval [bind VarHelperBind <Escape>]
|
||||
Editor::VarHelperEscape $widget
|
||||
}
|
||||
default {
|
||||
$widget insert "insert" $A
|
||||
# eval [bind VarHelperBind <Escape>]
|
||||
Editor::VarHelperEscape $widget
|
||||
}
|
||||
}
|
||||
} ;# proc auto_completition_key
|
||||
proc VarHelperEscape {w} {
|
||||
# puts ">>>>>>>>>>>> VarHelperEscape <<<<<<<<<<<<<<<<"
|
||||
# bindtags $w [list [winfo parent $w] $w Text sysAfter all]
|
||||
bindtags $w [list [winfo toplevel $w] $w Ctext sysAfter all]
|
||||
catch { destroy .varhelper }
|
||||
DebugPuts [bindtags $w]
|
||||
DebugPuts [bind $w]
|
||||
|
||||
}
|
||||
proc VarHelper {x y w word wordType} {
|
||||
global editors lexers variables
|
||||
variable txt
|
||||
variable win
|
||||
# set txt $w.frmText.t
|
||||
# блокировка открытия диалога если запущен другой
|
||||
set txt $w
|
||||
# set win .varhelper
|
||||
# Проверяем если есть выделение то блокировать появление диалога
|
||||
if {[$txt tag ranges sel] != ""} {
|
||||
DebugPuts "You have selected text [$txt tag ranges sel]"
|
||||
return
|
||||
}
|
||||
# puts "$x $y $w $word $wordType"
|
||||
set fileType [dict get $editors $txt fileType]
|
||||
|
||||
if {[dict exists $editors $txt variableList] != 0} {
|
||||
set varList [dict get $editors $txt variableList]
|
||||
# puts $varList
|
||||
}
|
||||
if {[dict exists $editors $txt procedureList] != 0} {
|
||||
set procList [dict get $editors $txt procedureList]
|
||||
}
|
||||
# puts $procList
|
||||
# puts ">>>>>>>[dict get $lexers $fileType commands]"
|
||||
if {[dict exists $lexers $fileType commands] !=0} {
|
||||
foreach i [dict get $lexers $fileType commands] {
|
||||
# puts $i
|
||||
lappend procList $i
|
||||
}
|
||||
}
|
||||
|
||||
# if {[dict exists $editors $txt variableList] == 0 && [dict exists $editors $txt procedureList] == 0} {
|
||||
# return
|
||||
# }
|
||||
set findedVars ""
|
||||
switch -- $wordType {
|
||||
vars {
|
||||
foreach i [lsearch -nocase -all $varList $word*] {
|
||||
# puts [lindex $varList $i]
|
||||
set item [lindex [lindex $varList $i] 0]
|
||||
# puts $item
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
# puts $item
|
||||
}
|
||||
}
|
||||
}
|
||||
procedure {
|
||||
foreach i [lsearch -nocase -all $procList $word*] {
|
||||
# puts [lindex $varList $i]
|
||||
set item [lindex [lindex $procList $i] 0]
|
||||
# puts $item
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
# puts $item
|
||||
}
|
||||
}
|
||||
}
|
||||
default {
|
||||
foreach i [lsearch -nocase -all $varList $word*] {
|
||||
# puts [lindex $varList $i]
|
||||
set item [lindex [lindex $varList $i] 0]
|
||||
# puts $item
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
# puts $item
|
||||
}
|
||||
}
|
||||
foreach i [lsearch -nocase -all $procList $word*] {
|
||||
# puts [lindex $varList $i]
|
||||
set item [lindex [lindex $procList $i] 0]
|
||||
# puts $item
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
# puts $item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# unset item
|
||||
# bindtags $txt [list VarHelperBind [winfo toplevel $txt] $txt Ctext sysAfter all]
|
||||
# bindtags $txt.t [list VarHelperBind [winfo parent $txt.t] $txt.t Text sysAfter all]
|
||||
# bind VarHelperBind <Escape> "Editor::VarHelperEscape $txt.t; break"
|
||||
# # bindtags $txt.t {[list [winfo parent $txt.t] $txt.t Text sysAfter all]};
|
||||
# # bindtags $txt {[list [winfo toplevel $txt] $txt Ctext sysAfter all]};
|
||||
# # catch { destroy .varhelper }"
|
||||
# bind VarHelperBind <Key> {Editor::VarHelperKey %W %K %A; break}
|
||||
#
|
||||
if {$findedVars eq ""} {
|
||||
proc ReleaseKey {k txt fileType} {
|
||||
global cfgVariables lexers returnProcessed
|
||||
# Если Return уже обработан в SelectFromList, пропускаем
|
||||
# puts "$returnProcessed $k"
|
||||
if {$k eq "Return" && [info exists returnProcessed]} {
|
||||
unset returnProcessed
|
||||
return
|
||||
}
|
||||
# puts $findedVars
|
||||
VarHelperDialog $x $y $w $word $findedVars
|
||||
|
||||
}
|
||||
|
||||
proc VarHelperDialog {x y w word findedVars} {
|
||||
global editors lexers variables
|
||||
variable txt
|
||||
variable win
|
||||
# puts ">>>>>>>>>>>>>$x $y $w $word $findedVars"
|
||||
# set txt $w.frmText.t
|
||||
# блокировка открытия диалога если запущен другой
|
||||
# if [winfo exists .findVariables] {
|
||||
# return
|
||||
# }
|
||||
# if { [winfo exists $win] } { destroy $win }
|
||||
set txt $w
|
||||
set win .varhelper
|
||||
# if {$findedVars eq ""} {
|
||||
# return
|
||||
# }
|
||||
toplevel $win
|
||||
wm transient $win .
|
||||
wm overrideredirect $win 1
|
||||
|
||||
listbox $win.lBox -width 30 -border 0
|
||||
pack $win.lBox -expand true -fill y -side left
|
||||
|
||||
foreach { item } $findedVars {
|
||||
$win.lBox insert end $item
|
||||
}
|
||||
|
||||
catch { $win.lBox activate 0 ; $win.lBox selection set 0 0 }
|
||||
|
||||
if { [set height [llength $findedVars]] > 10 } { set height 10 }
|
||||
$win.lBox configure -height $height
|
||||
|
||||
# focus $win.lBox
|
||||
|
||||
bind $win <Escape> {
|
||||
destroy $Editor::win
|
||||
focus -force $Editor::txt.t
|
||||
break
|
||||
}
|
||||
bind $win.lBox <Escape> {
|
||||
destroy $Editor::win
|
||||
focus -force $Editor::txt.t
|
||||
break
|
||||
}
|
||||
bind VarHelperBind <Control-Return> {
|
||||
$Editor::txt delete "insert - 1 chars wordstart" "insert wordend - 1 chars"
|
||||
$Editor::txt insert "insert" [.varhelper.lBox get [.varhelper.lBox curselection]]
|
||||
# eval [bind VarHelperBind <Escape>]
|
||||
Editor::VarHelperEscape $Editor::txt
|
||||
break
|
||||
}
|
||||
|
||||
# Определям расстояние до края экрана (основного окна) и если
|
||||
# оно меньше размера окна со списком то сдвигаем его вверх
|
||||
set winGeomY [winfo reqheight $win]
|
||||
set winGeomX [winfo reqwidth $win]
|
||||
|
||||
set topHeight [winfo height .]
|
||||
set topWidth [winfo width .]
|
||||
set topLeftUpperX [winfo x .]
|
||||
set topLeftUpperY [winfo y .]
|
||||
set topRightLowerX [expr $topLeftUpperX + $topWidth]
|
||||
set topRightLowerY [expr $topLeftUpperY + $topHeight]
|
||||
|
||||
if {[expr [expr $x + $winGeomX] > $topRightLowerX]} {
|
||||
set x [expr $x - $winGeomX]
|
||||
}
|
||||
if {[expr [expr $y + $winGeomY] > $topRightLowerY]} {
|
||||
set y [expr $y - $winGeomY]
|
||||
}
|
||||
|
||||
wm geom $win +$x+$y
|
||||
}
|
||||
|
||||
proc ReleaseKey {k txt fileType} {
|
||||
global cfgVariables lexers
|
||||
#
|
||||
set pos [$txt index insert]
|
||||
set lineNum [lindex [split $pos "."] 0]
|
||||
set posNum [lindex [split $pos "."] 1]
|
||||
@@ -645,8 +425,53 @@ namespace eval Editor {
|
||||
unset lpos
|
||||
$txt tag remove lightSelected 1.0 end
|
||||
|
||||
if { [winfo exists .varhelper] } { destroy .varhelper }
|
||||
# puts $k
|
||||
# Обработка ввода для показа окна с подсказками.
|
||||
# if { [winfo exists .varhelper] } { destroy .varhelper }
|
||||
# Флаг, нужно ли показывать новый список
|
||||
set showNewList 1
|
||||
|
||||
# Проверяем окно списка
|
||||
if {[winfo exists .varhelper]} {
|
||||
# Определяем, какая клавиша отпущена
|
||||
switch -- $k {
|
||||
Up - Down {
|
||||
# Стрелки - управление списком, окно остается
|
||||
# НЕ показываем новый список
|
||||
set showNewList 0
|
||||
return
|
||||
}
|
||||
Return {
|
||||
# Enter - выберет элемент, окно закроется в SelectFromList
|
||||
# НЕ показываем новый список
|
||||
set showNewList 0
|
||||
return
|
||||
}
|
||||
Escape {
|
||||
# Escape - закрыть окно
|
||||
destroy .varhelper
|
||||
set ::Helper::listActive 0
|
||||
Helper::VarHelperBindingsRestore $txt
|
||||
# НЕ показываем новый список
|
||||
set showNewList 0
|
||||
return
|
||||
}
|
||||
Control_L - Control_R - Alt_L - Alt_R - Shift_L - Shift_R {
|
||||
# Модификаторы - окно остается
|
||||
# НЕ показываем новый список
|
||||
set showNewList 0
|
||||
return
|
||||
}
|
||||
default {
|
||||
# Любая другая клавиша (буквы, цифры, пробел, Tab и т.д.)
|
||||
# закрывает окно списка, но ПОКАЗЫВАЕМ новый список
|
||||
destroy .varhelper
|
||||
set ::Helper::listActive 0
|
||||
Helper::VarHelperBindingsRestore $txt
|
||||
# showNewList остается = 1 (показываем новый список)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch $k {
|
||||
Return {
|
||||
regexp {^(\s*)} [$txt get [expr $lineNum - 1].0 [expr $lineNum - 1].end] -> spaceStart
|
||||
@@ -690,10 +515,68 @@ namespace eval Editor {
|
||||
if {$cfgVariables(variableHelper) eq "true"} {
|
||||
if {[dict exists $lexers $fileType variableSymbol] != 0} {
|
||||
set varSymbol [dict get $lexers $fileType variableSymbol]
|
||||
set lastSymbol [string last $varSymbol [$txt get $lineNum.0 $pos]]
|
||||
set lineText [$txt get $lineNum.0 $pos]
|
||||
# # Ищем переменную с помощью регулярного выражения
|
||||
# # Паттерн ищет $ за которым идет имя переменной И курсор сразу после имени
|
||||
# if {[regexp "(\\$)(\[a-zA-Z_:\]\[a-zA-Z0-9_:\]*)\$" $lineText -> symbol varName]} {
|
||||
# # Проверяем, что найденный $ - это действительно начало переменной
|
||||
# # (а не часть строки или другого символа)
|
||||
# DebugPuts "Found variable: $symbol$varName"
|
||||
#
|
||||
# # Дополнительная проверка: перед $ не должно быть обратного слэша (экранирование)
|
||||
# set posOfVarSymbol [string last $varSymbol $lineText]
|
||||
# if {$posOfVarSymbol > 0} {
|
||||
# set charBefore [string index $lineText [expr {$posOfVarSymbol - 1}]]
|
||||
# if {$charBefore eq "\\"} {
|
||||
# DebugPuts "Dollar sign is escaped, skipping"
|
||||
# return
|
||||
# }
|
||||
# }
|
||||
# Helper::VarHelper $box_x $box_y $txt $varName vars
|
||||
# }
|
||||
DebugPuts "Line text: '$lineText'"
|
||||
|
||||
# Проверяем, есть ли $ в строке
|
||||
set lastSymbol [string last $varSymbol $lineText]
|
||||
if {$lastSymbol ne "-1"} {
|
||||
set word [string trim [$txt get $lineNum.[expr $lastSymbol + 1] $pos]]
|
||||
Editor::VarHelper $box_x $box_y $txt $word vars
|
||||
# Проверяем экранирование
|
||||
if {$lastSymbol > 0} {
|
||||
set charBefore [string index $lineText [expr {$lastSymbol - 1}]]
|
||||
if {$charBefore eq "\\"} {
|
||||
DebugPuts "Dollar sign is escaped, skipping"
|
||||
return
|
||||
}
|
||||
}
|
||||
# Берем текст после $
|
||||
set afterDollar [string range $lineText [expr {$lastSymbol + 1}] end]
|
||||
DebugPuts "Text after $varSymbol: '$afterDollar'"
|
||||
# Если после $ ничего нет (только что ввели $) - показываем все переменные
|
||||
if {$afterDollar eq ""} {
|
||||
DebugPuts "Just typed $varSymbol, showing all variables"
|
||||
Helper::VarHelper $box_x $box_y $txt "" vars
|
||||
return
|
||||
}
|
||||
# Проверяем, что введено после $
|
||||
if {[regexp {^([a-zA-Z_:][a-zA-Z0-9_:]*)?$} $afterDollar -> varName]} {
|
||||
# Вариант 1: regexp с концом строки - курсор сразу после (возможного) имени
|
||||
DebugPuts "Cursor after variable name (or $varSymbol only): '$varName'"
|
||||
Helper::VarHelper $box_x $box_y $txt $varName vars
|
||||
} elseif {[regexp {^([a-zA-Z_:][a-zA-Z0-9_:]*)} $afterDollar -> varName]} {
|
||||
# Вариант 2: есть имя переменной, но курсор не обязательно сразу после
|
||||
DebugPuts "Found variable name: '$varName'"
|
||||
# Проверяем позицию курсора
|
||||
set varEndPos [expr {[string length $varName] + 1}] ; # +1 для $
|
||||
|
||||
if {$varEndPos == [string length $lineText]} {
|
||||
# Курсор сразу после имени
|
||||
Helper::VarHelper $box_x $box_y $txt $varName vars
|
||||
} else {
|
||||
DebugPuts "Cursor not immediately after variable name, skipping"
|
||||
}
|
||||
} else {
|
||||
# После $ что-то недопустимое (например, цифра, скобка и т.д.)
|
||||
DebugPuts "Invalid characters after $varSymbol"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set ind [$txt search -backwards -regexp {\W} $pos {insert linestart}]
|
||||
@@ -705,8 +588,9 @@ namespace eval Editor {
|
||||
# set ind [$txt search -backwards -regexp {^} $pos {insert linestart}]
|
||||
set word [$txt get {insert linestart} $pos]
|
||||
}
|
||||
DebugPuts "> Extracted word: '$word'"
|
||||
if {$word ne ""} {
|
||||
Editor::VarHelper $box_x $box_y $txt $word {}
|
||||
Helper::VarHelper $box_x $box_y $txt $word {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -722,7 +606,7 @@ namespace eval Editor {
|
||||
set word [$txt get {insert linestart} $pos]
|
||||
}
|
||||
if {$word ne ""} {
|
||||
Editor::VarHelper $box_x $box_y $txt $word procedure
|
||||
Helper::VarHelper $box_x $box_y $txt $word procedure
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
340
lib/helper.tcl
Normal file
340
lib/helper.tcl
Normal file
@@ -0,0 +1,340 @@
|
||||
namespace eval Helper {
|
||||
variable ::originalBindings {}
|
||||
# Флаг, указывающий, что окно со списком активно
|
||||
variable ::listActive 0
|
||||
# Переменная для отслеживания предыдущего ввода (чтобы не обновлять список без необходимости)
|
||||
variable ::previousInput ""
|
||||
|
||||
proc VarHelperKey { widget K A } {
|
||||
set win .varhelper
|
||||
DebugPuts "Helper::VarHelperKey: K=$K, A='$A'"
|
||||
|
||||
# Проверяем, существует ли окно списка
|
||||
if {![winfo exists $win]} {
|
||||
DebugPuts "Window doesn't exist, restoring bindings"
|
||||
Helper::VarHelperBindingsRestore $widget
|
||||
set ::listActive 0
|
||||
return
|
||||
}
|
||||
|
||||
switch -- $K {
|
||||
<Up> {
|
||||
DebugPuts "Processing Up arrow"
|
||||
# Перемещаем выбор вверх
|
||||
set current [$win.lBox curselection]
|
||||
DebugPuts "Current selection: $current"
|
||||
|
||||
if {$current ne "" && $current > 0} {
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set [expr {$current - 1}]
|
||||
$win.lBox activate [expr {$current - 1}]
|
||||
$win.lBox see [expr {$current - 1}]
|
||||
} elseif {[$win.lBox size] > 0} {
|
||||
# Если ничего не выбрано, выбираем последний элемент
|
||||
set last [expr {[$win.lBox size] - 1}]
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set $last
|
||||
$win.lBox activate $last
|
||||
$win.lBox see $last
|
||||
}
|
||||
return -code break
|
||||
}
|
||||
<Down> {
|
||||
DebugPuts "Processing Down arrow"
|
||||
# Перемещаем выбор вниз
|
||||
set current [$win.lBox curselection]
|
||||
set size [$win.lBox size]
|
||||
DebugPuts "Current selection: $current, size: $size"
|
||||
|
||||
if {$current ne "" && $current < $size - 1} {
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set [expr {$current + 1}]
|
||||
$win.lBox activate [expr {$current + 1}]
|
||||
$win.lBox see [expr {$current + 1}]
|
||||
} elseif {$size > 0} {
|
||||
# Если ничего не выбрано, выбираем первый элемент
|
||||
$win.lBox selection clear 0 end
|
||||
$win.lBox selection set 0
|
||||
$win.lBox activate 0
|
||||
$win.lBox see 0
|
||||
}
|
||||
return -code break
|
||||
}
|
||||
<Return> {
|
||||
DebugPuts "Processing Return"
|
||||
Helper::SelectFromList $widget
|
||||
return -code break
|
||||
}
|
||||
<Escape> {
|
||||
DebugPuts "Processing Escape"
|
||||
# Закрываем окно списка
|
||||
wm withdraw $win
|
||||
set ::listActive 0
|
||||
Helper::VarHelperBindingsRestore $widget
|
||||
set ::previousInput ""
|
||||
focus $widget
|
||||
return -code break
|
||||
}
|
||||
default {
|
||||
DebugPuts "Default case for K=$K, A='$A'"
|
||||
# Для печатных символов
|
||||
if {$A ne ""} {
|
||||
DebugPuts "Inserting character '$A' and restoring bindings"
|
||||
# Восстанавливаем привязки перед вставкой
|
||||
Helper::VarHelperBindingsRestore $widget
|
||||
# Вставляем символ
|
||||
$widget insert "insert" $A
|
||||
}
|
||||
return -code break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc VarHelper {x y w word wordType} {
|
||||
global editors lexers variables
|
||||
variable txt
|
||||
variable win
|
||||
|
||||
DebugPuts "=== VarHelper called: word='$word', wordType='$wordType' ==="
|
||||
|
||||
set txt $w
|
||||
# Проверяем если есть выделение то блокировать появление диалога
|
||||
if {[$txt tag ranges sel] != ""} {
|
||||
DebugPuts "You have selected text [$txt tag ranges sel]"
|
||||
return
|
||||
}
|
||||
|
||||
set fileType [dict get $editors $txt fileType]
|
||||
|
||||
if {[dict exists $editors $txt variableList] != 0} {
|
||||
set varList [dict get $editors $txt variableList]
|
||||
} else {
|
||||
set varList {}
|
||||
}
|
||||
if {[dict exists $editors $txt procedureList] != 0} {
|
||||
set procList [dict get $editors $txt procedureList]
|
||||
} else {
|
||||
set procList {}
|
||||
}
|
||||
|
||||
if {[dict exists $lexers $fileType commands] != 0} {
|
||||
foreach i [dict get $lexers $fileType commands] {
|
||||
lappend procList $i
|
||||
}
|
||||
}
|
||||
|
||||
set findedVars ""
|
||||
switch -- $wordType {
|
||||
vars {
|
||||
foreach i [lsearch -nocase -all $varList $word*] {
|
||||
set item [lindex [lindex $varList $i] 0]
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
}
|
||||
}
|
||||
}
|
||||
procedure {
|
||||
foreach i [lsearch -nocase -all $procList $word*] {
|
||||
set item [lindex [lindex $procList $i] 0]
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
}
|
||||
}
|
||||
}
|
||||
default {
|
||||
foreach i [lsearch -nocase -all $varList $word*] {
|
||||
set item [lindex [lindex $varList $i] 0]
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
}
|
||||
}
|
||||
foreach i [lsearch -nocase -all $procList $word*] {
|
||||
set item [lindex [lindex $procList $i] 0]
|
||||
if {[lsearch $findedVars $item] eq "-1"} {
|
||||
lappend findedVars $item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DebugPuts "Found [llength $findedVars] items: $findedVars"
|
||||
|
||||
if {$findedVars eq ""} {
|
||||
DebugPuts "No items found, returning"
|
||||
return
|
||||
}
|
||||
|
||||
VarHelperDialog $x $y $w $word $findedVars
|
||||
}
|
||||
|
||||
proc VarHelperDialog {x y w word findedVars} {
|
||||
variable txt
|
||||
variable win
|
||||
|
||||
set txt $w
|
||||
set win .varhelper
|
||||
|
||||
DebugPuts "VarHelperDialog called with [llength $findedVars] items"
|
||||
|
||||
# Если окно уже существует, уничтожаем его
|
||||
if {[winfo exists $win]} {
|
||||
DebugPuts "Window already exists, destroying it"
|
||||
destroy $win
|
||||
Helper::VarHelperBindingsRestore $txt
|
||||
}
|
||||
|
||||
toplevel $win
|
||||
wm transient $win .
|
||||
wm overrideredirect $win 1
|
||||
|
||||
listbox $win.lBox -width 30 -border 0
|
||||
pack $win.lBox -expand true -fill y -side left
|
||||
|
||||
foreach item $findedVars {
|
||||
$win.lBox insert end $item
|
||||
}
|
||||
|
||||
DebugPuts "Listbox created with [llength $findedVars] items"
|
||||
|
||||
# Выбираем первый элемент
|
||||
if {[llength $findedVars] > 0} {
|
||||
$win.lBox selection set 0
|
||||
$win.lBox activate 0
|
||||
}
|
||||
|
||||
if {[set height [llength $findedVars]] > 10} {
|
||||
set height 10
|
||||
}
|
||||
$win.lBox configure -height $height
|
||||
|
||||
Helper::VarHelperBindingsSetup $w
|
||||
|
||||
# Привязка для закрытия окна списка
|
||||
bind $win <Destroy> [list apply {{win txt} {
|
||||
set ::listActive 0
|
||||
Helper::VarHelperBindingsRestore $txt
|
||||
set ::previousInput ""
|
||||
}} $win $txt.t]
|
||||
|
||||
# Определяем расстояние до края экрана (основного окна) и если
|
||||
# оно меньше размера окна со списком то сдвигаем его вверх
|
||||
set winGeomY [winfo reqheight $win]
|
||||
set winGeomX [winfo reqwidth $win]
|
||||
|
||||
set topHeight [winfo height .]
|
||||
set topWidth [winfo width .]
|
||||
set topLeftUpperX [winfo x .]
|
||||
set topLeftUpperY [winfo y .]
|
||||
set topRightLowerX [expr $topLeftUpperX + $topWidth]
|
||||
set topRightLowerY [expr $topLeftUpperY + $topHeight]
|
||||
|
||||
if {[expr $x + $winGeomX] > $topRightLowerX} {
|
||||
set x [expr $x - $winGeomX]
|
||||
}
|
||||
if {[expr $y + $winGeomY] > $topRightLowerY} {
|
||||
set y [expr $y - $winGeomY]
|
||||
}
|
||||
set ::listActive 1
|
||||
DebugPuts "Showing window at +$x+$y"
|
||||
wm geom $win +$x+$y
|
||||
}
|
||||
|
||||
proc VarHelperBindingsSetup {txt} {
|
||||
DebugPuts "Setting up bindings for $txt"
|
||||
|
||||
# Сбрасываем сохраненные привязки
|
||||
set ::originalBindings {}
|
||||
|
||||
# Список событий для перехвата
|
||||
set events {<Up> <Down> <Return>}
|
||||
|
||||
# Сохраняем и заменяем привязки
|
||||
foreach event $events {
|
||||
# Получаем текущую привязку
|
||||
set original [bind $txt $event]
|
||||
DebugPuts " Saving binding for $event: '$original'"
|
||||
|
||||
# Сохраняем оригинал
|
||||
lappend ::originalBindings [list $event $original]
|
||||
|
||||
# Устанавливаем новую привязку
|
||||
bind $txt $event [list Helper::VarHelperKey $txt $event %A]
|
||||
}
|
||||
}
|
||||
|
||||
# Восстановление оригинальных привязок
|
||||
proc VarHelperBindingsRestore {txt} {
|
||||
DebugPuts "Restoring bindings for $txt"
|
||||
DebugPuts "Have [llength $::originalBindings] bindings to restore"
|
||||
|
||||
if {![info exists ::originalBindings]} {
|
||||
DebugPuts " No original bindings stored"
|
||||
# Очищаем наши привязки
|
||||
foreach event {<Up> <Down> <Return>} {
|
||||
bind $txt $event {}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
# Восстанавливаем оригинальные привязки
|
||||
foreach binding $::originalBindings {
|
||||
set event [lindex $binding 0]
|
||||
set command [lindex $binding 1]
|
||||
DebugPuts " Restoring $event: '$command'"
|
||||
|
||||
if {$command eq ""} {
|
||||
bind $txt $event {}
|
||||
} else {
|
||||
bind $txt $event $command
|
||||
}
|
||||
}
|
||||
|
||||
# Очищаем сохраненные привязки
|
||||
set ::originalBindings {}
|
||||
}
|
||||
|
||||
proc SelectFromList {txt} {
|
||||
global returnProcessed editors lexers
|
||||
set win .varhelper
|
||||
# puts "[dict get $editors $txt fileType]"
|
||||
# puts "[dict get $lexers [dict get $editors $txt fileType] variableSymbol]"
|
||||
|
||||
if {![winfo exists $win]} {
|
||||
return
|
||||
}
|
||||
set selected [$win.lBox curselection]
|
||||
if {$selected ne ""} {
|
||||
set text [string trim [$win.lBox get $selected]]
|
||||
# DebugPuts "[dict exists $lexers [dict get $editors $txt fileType] variableSymbol]"
|
||||
if [dict exists $lexers [dict get $editors $txt fileType] variableSymbol] {
|
||||
set varSymbol [dict get $lexers [dict get $editors $txt fileType] variableSymbol]
|
||||
} else {
|
||||
set varSymbol ""
|
||||
}
|
||||
# Опеределяем что символ перед позицией вставки равен символу переменной из настроек lexers
|
||||
# если равен то вставляем выбранное из списка сразу за ним
|
||||
# если нет то удаляем введенный текст до этого символа и вставляем выбранное из списка
|
||||
if {[$txt get "insert - 1 char" "insert"] eq $varSymbol} {
|
||||
$txt insert "insert" $text
|
||||
} else {
|
||||
$txt delete "insert - 1 chars wordstart" "insert wordend - 1 chars"
|
||||
$txt insert "insert" $text
|
||||
}
|
||||
# Закрываем окно
|
||||
destroy $win
|
||||
set ::listActive 0
|
||||
Helper::VarHelperBindingsRestore $txt
|
||||
set ::previousInput ""
|
||||
|
||||
# Устанавливаем флаг, что Return уже обработан
|
||||
set returnProcessed 1
|
||||
# after 10 {catch {unset returnProcessed}}
|
||||
|
||||
focus $txt.t
|
||||
}
|
||||
}
|
||||
proc DebugPuts {msg} {
|
||||
puts "DEBUG: $msg"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ proc ImageViewer {f w node} {
|
||||
#$w.scrwin setwidget $w.scrwin.f
|
||||
openImg $f $w.f.c $node
|
||||
}
|
||||
|
||||
|
||||
proc openImg {fn w node} {
|
||||
global im1 factor
|
||||
set im1 [image create photo -file $fn]
|
||||
|
||||
@@ -9,8 +9,8 @@ exec wish8.6 "$0" -- "$@"
|
||||
# Home page: https://nuk-svk.ru
|
||||
######################################################
|
||||
# Version: 2.0.0
|
||||
# Release: beta2
|
||||
# Build: 28012026124210
|
||||
# Release: beta3
|
||||
# Build: 29012026155729
|
||||
######################################################
|
||||
|
||||
# определим текущую версию, релиз и т.д.
|
||||
|
||||
Reference in New Issue
Block a user