Добавлено определение типа файла
This commit is contained in:
parent
11c3dd2fb2
commit
3cbc7c1f48
|
@ -28,6 +28,9 @@ editedFiles=
|
||||||
searchCommand=/usr/bin/grep
|
searchCommand=/usr/bin/grep
|
||||||
searchCommandOptions=-r -n -H
|
searchCommandOptions=-r -n -H
|
||||||
gitCommand=/usr/bin/git
|
gitCommand=/usr/bin/git
|
||||||
|
# must return a mime type of file
|
||||||
|
fileTypeCommand=/usr/bin/file
|
||||||
|
fileTypeCommandOptions=-i -b
|
||||||
\[GUI\]
|
\[GUI\]
|
||||||
locale=$locale
|
locale=$locale
|
||||||
theme=dark
|
theme=dark
|
||||||
|
|
|
@ -1355,6 +1355,17 @@ namespace eval Editor {
|
||||||
|
|
||||||
proc Editor {fileFullPath nb itemName} {
|
proc Editor {fileFullPath nb itemName} {
|
||||||
global cfgVariables editors
|
global cfgVariables editors
|
||||||
|
set imageType {
|
||||||
|
PNG
|
||||||
|
JPG
|
||||||
|
JPEG
|
||||||
|
WEBP
|
||||||
|
GIF
|
||||||
|
TIFF
|
||||||
|
JP2
|
||||||
|
ICO
|
||||||
|
XPM
|
||||||
|
}
|
||||||
set fr $itemName
|
set fr $itemName
|
||||||
if ![string match "*untitled*" $itemName] {
|
if ![string match "*untitled*" $itemName] {
|
||||||
set lblText $fileFullPath
|
set lblText $fileFullPath
|
||||||
|
@ -1386,8 +1397,11 @@ namespace eval Editor {
|
||||||
pack propagate $fr.panelTxt false
|
pack propagate $fr.panelTxt false
|
||||||
pack $fr.panelTxt -side top -fill both -expand true
|
pack $fr.panelTxt -side top -fill both -expand true
|
||||||
|
|
||||||
|
if {[lsearch -exact $imageType $fileType] != -1} {
|
||||||
|
ImageViewer $fileFullPath $itemName $fr
|
||||||
|
} else {
|
||||||
set frmText [Editor::EditorWidget $fr $fileType]
|
set frmText [Editor::EditorWidget $fr $fileType]
|
||||||
|
}
|
||||||
$fr.panelTxt add $frmText -weight 0
|
$fr.panelTxt add $frmText -weight 0
|
||||||
|
|
||||||
return $fr
|
return $fr
|
||||||
|
|
106
lib/files.tcl
106
lib/files.tcl
|
@ -15,6 +15,94 @@ namespace eval FileOper {
|
||||||
{"All files" *}
|
{"All files" *}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc GetFileType {fileFullPath {opt ""}} {
|
||||||
|
global cfgVariables
|
||||||
|
# Проверям наличие программы в системе, если есть то добавляем опции
|
||||||
|
# если нет то используем тиклевый пакет
|
||||||
|
if [file exists $cfgVariables(fileTypeCommand)] {
|
||||||
|
set cmd exec
|
||||||
|
lappend cmd $cfgVariables(fileTypeCommand)
|
||||||
|
foreach _ [split $cfgVariables(fileTypeCommandOptions) " "] {
|
||||||
|
lappend cmd $_
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set cmd [list eval ::fileutil::magic::filetype]
|
||||||
|
}
|
||||||
|
|
||||||
|
# lappend cmd $activeProject
|
||||||
|
lappend cmd $fileFullPath
|
||||||
|
catch $cmd pipe
|
||||||
|
puts $pipe
|
||||||
|
if [regexp -nocase -- {(\w+)/([[:alnum:]-]+); charset=([[:alnum:]-]+)} $pipe m fType fExt fCharset] {
|
||||||
|
puts "$fType $fExt $fCharset"
|
||||||
|
}
|
||||||
|
switch $opt {
|
||||||
|
"charset" {
|
||||||
|
if [info exists fCharset] {
|
||||||
|
return $fCharset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch $fType {
|
||||||
|
"application" {
|
||||||
|
if {$fExt ne "json"} {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"text" {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
"image" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
## GETTING FILE ATTRIBUTES ##
|
||||||
|
proc GetFileAttr {file {opt ""}} {
|
||||||
|
global tcl_platform
|
||||||
|
set fileAttribute ""
|
||||||
|
# get file modify time
|
||||||
|
switch $opt {
|
||||||
|
attr {
|
||||||
|
if {$tcl_platform(platform) == "windows"} {
|
||||||
|
set unixTime [file mtime $file]
|
||||||
|
set modifyTime [clock format $unixTime -format "%d/%m/%Y, %H:%M"]
|
||||||
|
} elseif {$tcl_platform(platform) == "mac"} {
|
||||||
|
|
||||||
|
} elseif {$tcl_platform(platform) == "unix"} {
|
||||||
|
set unixTime [file mtime $file]
|
||||||
|
set modifyTime [clock format $unixTime -format "%d/%m/%Y, %H:%M"]
|
||||||
|
}
|
||||||
|
return $modifyTime
|
||||||
|
}
|
||||||
|
size {
|
||||||
|
# get file size
|
||||||
|
set size [file size $file]
|
||||||
|
if {$size < 1024} {
|
||||||
|
set fileSize "$size b"
|
||||||
|
}
|
||||||
|
if {$size >= 1024} {
|
||||||
|
set s [expr ($size.0) / 1024]
|
||||||
|
set dot [string first "\." $s]
|
||||||
|
set int [string range $s 0 [expr $dot - 1]]
|
||||||
|
set dec [string range $s [expr $dot + 1] [expr $dot + 2]]
|
||||||
|
set fileSize "$int.$dec Kb"
|
||||||
|
}
|
||||||
|
if {$size >= 1048576} {
|
||||||
|
set s [expr ($size.0) / 1048576]
|
||||||
|
set dot [string first "\." $s]
|
||||||
|
set int [string range $s 0 [expr $dot - 1]]
|
||||||
|
set dec [string range $s [expr $dot + 1] [expr $dot + 2]]
|
||||||
|
set fileSize "$int.$dec Mb"
|
||||||
|
}
|
||||||
|
return $fileSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
proc OpenDialog {} {
|
proc OpenDialog {} {
|
||||||
global env project activeProject
|
global env project activeProject
|
||||||
if [info exists activeProject] {
|
if [info exists activeProject] {
|
||||||
|
@ -270,8 +358,21 @@ namespace eval FileOper {
|
||||||
global nbEditor tree
|
global nbEditor tree
|
||||||
if {[file exists $fileFullPath] == 0} {
|
if {[file exists $fileFullPath] == 0} {
|
||||||
return false
|
return false
|
||||||
|
} else {
|
||||||
|
# puts [::fileutil::magic::filetype $fileFullPath]
|
||||||
|
set fileType [FileOper::GetFileType $fileFullPath]
|
||||||
|
}
|
||||||
|
switch $fileType {
|
||||||
|
"text" {
|
||||||
|
# return text
|
||||||
|
}
|
||||||
|
"image" {
|
||||||
|
# return image
|
||||||
|
}
|
||||||
|
false {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set filePath [file dirname $fileFullPath]
|
set filePath [file dirname $fileFullPath]
|
||||||
set fileName [file tail $fileFullPath]
|
set fileName [file tail $fileFullPath]
|
||||||
regsub -all {\.|/|\\|\s} $fileFullPath "_" itemName
|
regsub -all {\.|/|\\|\s} $fileFullPath "_" itemName
|
||||||
|
@ -291,7 +392,8 @@ namespace eval FileOper {
|
||||||
$itemName.frmText.t.t mark set insert 1.0
|
$itemName.frmText.t.t mark set insert 1.0
|
||||||
$itemName.frmText.t.t see 1.0
|
$itemName.frmText.t.t see 1.0
|
||||||
focus -force $itemName.frmText.t.t
|
focus -force $itemName.frmText.t.t
|
||||||
|
.frmStatus.lblSize configure -text [GetFileAttr $fileFullPath "size"]
|
||||||
|
.frmStatus.lblEncoding configure -text [GetFileType $fileFullPath "charset"]
|
||||||
return $itemName
|
return $itemName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,15 @@ pack .frmStatus -side top -padx 1 -fill x
|
||||||
# pack .panel -expand true -fill both
|
# pack .panel -expand true -fill both
|
||||||
# pack propagate .panel false
|
# pack propagate .panel false
|
||||||
#pack [label .frmMenu.lbl -text "ddd"]
|
#pack [label .frmMenu.lbl -text "ddd"]
|
||||||
|
|
||||||
pack [ttk::label .frmStatus.lblGitLogo -justify left] -side left
|
pack [ttk::label .frmStatus.lblGitLogo -justify left] -side left
|
||||||
pack [ttk::label .frmStatus.lblGit] -side left
|
pack [ttk::label .frmStatus.lblGit] -side left -exp and true -fill x
|
||||||
bind .frmStatus.lblGit <Button-1><ButtonRelease-1> {
|
bind .frmStatus.lblGit <Button-1><ButtonRelease-1> {
|
||||||
Git::BranchDialog %X %Y
|
Git::BranchDialog %X %Y
|
||||||
}
|
}
|
||||||
|
pack [ttk::label .frmStatus.lblSize -justify center] -side left -expand true -fill x
|
||||||
pack [ttk::label .frmStatus.lblPosition -justify right] -side right
|
pack [ttk::label .frmStatus.lblEncoding -justify center] -side left -expand true -fill x
|
||||||
|
pack [ttk::label .frmStatus.lblPosition -justify right] -side right -expand true -fill x
|
||||||
|
|
||||||
ttk::menubutton .frmMenu.mnuFile -text [::msgcat::mc "File"] -menu .frmMenu.mnuFile.m
|
ttk::menubutton .frmMenu.mnuFile -text [::msgcat::mc "File"] -menu .frmMenu.mnuFile.m
|
||||||
GetFileMenu [menu .frmMenu.mnuFile.m]
|
GetFileMenu [menu .frmMenu.mnuFile.m]
|
||||||
|
|
|
@ -10,7 +10,7 @@ exec wish "$0" -- "$@"
|
||||||
######################################################
|
######################################################
|
||||||
# Version: 2.0.0
|
# Version: 2.0.0
|
||||||
# Release: alpha
|
# Release: alpha
|
||||||
# Build: 09112022145404
|
# Build: 09112022170027
|
||||||
######################################################
|
######################################################
|
||||||
|
|
||||||
# определим текущую версию, релиз и т.д.
|
# определим текущую версию, релиз и т.д.
|
||||||
|
@ -47,6 +47,7 @@ package require ctext
|
||||||
package require base64
|
package require base64
|
||||||
package require fileutil
|
package require fileutil
|
||||||
package require Thread
|
package require Thread
|
||||||
|
package require fileutil::magic::filetype
|
||||||
|
|
||||||
# Устанавливаем текущий каталог
|
# Устанавливаем текущий каталог
|
||||||
set dir(root) [pwd]
|
set dir(root) [pwd]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user