From 3cbc7c1f48637cd676f4c8ba8a3f881eb92b691d Mon Sep 17 00:00:00 2001 From: svkalinin Date: Thu, 10 Nov 2022 14:53:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B8=D0=BF=D0=B0=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.tcl | 3 ++ lib/editor.tcl | 18 ++++++++- lib/files.tcl | 108 +++++++++++++++++++++++++++++++++++++++++++++++-- lib/gui.tcl | 8 ++-- projman.tcl | 3 +- 5 files changed, 131 insertions(+), 9 deletions(-) diff --git a/lib/config.tcl b/lib/config.tcl index 636072a..6b878e3 100644 --- a/lib/config.tcl +++ b/lib/config.tcl @@ -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 diff --git a/lib/editor.tcl b/lib/editor.tcl index 33a3faa..b18a8b5 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -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 diff --git a/lib/files.tcl b/lib/files.tcl index 91e985b..fccc417 100644 --- a/lib/files.tcl +++ b/lib/files.tcl @@ -13,7 +13,95 @@ namespace eval FileOper { set ::types { {"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 @@ -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 } diff --git a/lib/gui.tcl b/lib/gui.tcl index e449053..73d752a 100644 --- a/lib/gui.tcl +++ b/lib/gui.tcl @@ -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 { 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] diff --git a/projman.tcl b/projman.tcl index 1fa8d3f..c66e997 100755 --- a/projman.tcl +++ b/projman.tcl @@ -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]