Добавлено определение типа файла

This commit is contained in:
svkalinin 2022-11-10 14:53:58 +03:00
parent 11c3dd2fb2
commit 3cbc7c1f48
5 changed files with 131 additions and 9 deletions

View File

@ -28,6 +28,9 @@ editedFiles=
searchCommand=/usr/bin/grep
searchCommandOptions=-r -n -H
gitCommand=/usr/bin/git
# must return a mime type of file
fileTypeCommand=/usr/bin/file
fileTypeCommandOptions=-i -b
\[GUI\]
locale=$locale
theme=dark

View File

@ -1355,6 +1355,17 @@ namespace eval Editor {
proc Editor {fileFullPath nb itemName} {
global cfgVariables editors
set imageType {
PNG
JPG
JPEG
WEBP
GIF
TIFF
JP2
ICO
XPM
}
set fr $itemName
if ![string match "*untitled*" $itemName] {
set lblText $fileFullPath
@ -1386,8 +1397,11 @@ namespace eval Editor {
pack propagate $fr.panelTxt false
pack $fr.panelTxt -side top -fill both -expand true
set frmText [Editor::EditorWidget $fr $fileType]
if {[lsearch -exact $imageType $fileType] != -1} {
ImageViewer $fileFullPath $itemName $fr
} else {
set frmText [Editor::EditorWidget $fr $fileType]
}
$fr.panelTxt add $frmText -weight 0
return $fr

View File

@ -15,6 +15,94 @@ namespace eval FileOper {
{"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 {} {
global env project activeProject
if [info exists activeProject] {
@ -270,8 +358,21 @@ namespace eval FileOper {
global nbEditor tree
if {[file exists $fileFullPath] == 0} {
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 fileName [file tail $fileFullPath]
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 see 1.0
focus -force $itemName.frmText.t.t
.frmStatus.lblSize configure -text [GetFileAttr $fileFullPath "size"]
.frmStatus.lblEncoding configure -text [GetFileType $fileFullPath "charset"]
return $itemName
}

View File

@ -79,13 +79,15 @@ pack .frmStatus -side top -padx 1 -fill x
# pack .panel -expand true -fill both
# pack propagate .panel false
#pack [label .frmMenu.lbl -text "ddd"]
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> {
Git::BranchDialog %X %Y
}
pack [ttk::label .frmStatus.lblPosition -justify right] -side right
pack [ttk::label .frmStatus.lblSize -justify center] -side left -expand true -fill x
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
GetFileMenu [menu .frmMenu.mnuFile.m]

View File

@ -10,7 +10,7 @@ exec wish "$0" -- "$@"
######################################################
# Version: 2.0.0
# Release: alpha
# Build: 09112022145404
# Build: 09112022170027
######################################################
# определим текущую версию, релиз и т.д.
@ -47,6 +47,7 @@ package require ctext
package require base64
package require fileutil
package require Thread
package require fileutil::magic::filetype
# Устанавливаем текущий каталог
set dir(root) [pwd]