From ace5dc22f4548859889a318f5fa69c4c99f82b64 Mon Sep 17 00:00:00 2001 From: Sergey Kalinin Date: Mon, 12 Mar 2018 16:59:32 +0300 Subject: [PATCH] Added insert base64 encoded image into source code --- CHANGELOG | 5 +++++ lib/editor.tcl | 5 ++++- lib/filedialog.tcl | 2 -- lib/imgviewer.tcl | 26 +++++++++++++++++++------- lib/main.tcl | 1 + lib/menu.tcl | 14 +++++++++++++- msgs/en.msg | 2 ++ msgs/ru.msg | 2 ++ projman.tcl | 4 ++++ 9 files changed, 50 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6207988..5a43737 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ ########################################################## 0.4.5 +12.03.2018 +- Added insert base64 encoded image into source code (press "Control+I" or popup menu) + 06.03.2018 - Added procedure arguments into tree - Change read config procedure (error fixed) @@ -427,3 +430,5 @@ characters to the right of the insertion cursor. + + diff --git a/lib/editor.tcl b/lib/editor.tcl index 0bce7b1..a85a267 100644 --- a/lib/editor.tcl +++ b/lib/editor.tcl @@ -694,6 +694,7 @@ proc EditFile {tree node fileName} { bind $text "auto_completition_proc $text" bind $text "auto_completition_proc $text" #bind $text "auto_completition_proc $text" + bind $text "ImageBase64Encode $text" bind $text Find bind $text {TextOperation comment} @@ -933,7 +934,7 @@ proc ReadFileStructure {mod line lineNumber tree node} { global backUpFileCreate fileExt progress editor braceHighLightBG braceHighLightFG activeProject global varList set dot "_" - + # Insert procedure names into tree # regsub -all {\t} $line " " line set w $noteBook.f$node @@ -1001,3 +1002,5 @@ proc EditorFileNavigateMenu {w fullPathFile} { GetOp + + diff --git a/lib/filedialog.tcl b/lib/filedialog.tcl index 6668ebd..585be27 100644 --- a/lib/filedialog.tcl +++ b/lib/filedialog.tcl @@ -622,5 +622,3 @@ proc FileOperation::FileDialog {tree operation} { return 0 } } - - diff --git a/lib/imgviewer.tcl b/lib/imgviewer.tcl index 8940b61..458d321 100644 --- a/lib/imgviewer.tcl +++ b/lib/imgviewer.tcl @@ -1,6 +1,3 @@ -package require Img - - proc ImageViewer {f w node} { global tab_label noteBook factor im1 im2 editor set factor($node) 1.0 @@ -22,7 +19,7 @@ proc ImageViewer {f w node} { #$w.scrwin setwidget $w.scrwin.f openImg $f $w.f.c $node set tab_label [$noteBook itemcget $node -text] - balloon $w.f.c set "Mouse wheel up/down - vertiモal scrolling the image\n\ + balloon $w.f.c set "Mouse wheel up/down - vertiテ殿l scrolling the image\n\ Shift + mouse wheel up/down - horizontal image scrolling\n\ Control + mouse wheel up/down is a scale image -/+" } @@ -53,8 +50,23 @@ proc scale {w {n 1} node} { $w config -scrollregion [$w bbox all] } - - - +proc ImageBase64Encode {text} { + global env + set types { + {"GIF" {.gif}} + {"JPEG" {.jpg}} + {"PNG" {.png}} + {"BMP" {.bmp}} + {"All files" *} + } + set img [tk_getOpenFile -initialdir $env(HOME) -filetypes $types -parent .] + set f [open $img] + fconfigure $f -translation binary + set data [base64::encode [read $f]] + close $f + # base name on root name of the image file + set name [file root [file tail $img]] + $text insert [Position] "image create photo $name -data {\n$data\n}" +} diff --git a/lib/main.tcl b/lib/main.tcl index 9e0645f..36473e5 100644 --- a/lib/main.tcl +++ b/lib/main.tcl @@ -367,3 +367,4 @@ if {[info exists workingProject]} { } } + diff --git a/lib/menu.tcl b/lib/menu.tcl index 3893b6a..d219098 100644 --- a/lib/menu.tcl +++ b/lib/menu.tcl @@ -90,8 +90,18 @@ proc GetMenu {m} { $me add command -label [::msgcat::mc "KOI8-R"] -command {TextEncode koi8-r} -font $fontNormal $me add command -label [::msgcat::mc "CP1251"] -command {TextEncode cp1251} -font $fontNormal $me add command -label [::msgcat::mc "CP866"] -command {TextEncode cp866} -font $fontNormal + $m add separator + $m add command -label [::msgcat::mc "Insert image"] -font $fontNormal -accelerator "Ctrl+I" \ + -command { + set nb [$noteBook raise] + if {$nb == "" || $nb == "newproj" || $nb == "about" || $nb == "debug"} { + return + } + set nb "$noteBook.f$nb" + ImageBase64Encode $nb.text + unset nb + } } - proc GetViewMenu {m} { global fontNormal fontBold imgDir editor $m add checkbutton -label [::msgcat::mc "Show the Menu"] -font $fontNormal -state normal\ @@ -168,3 +178,5 @@ proc GetFileMenu {m} { } + + diff --git a/msgs/en.msg b/msgs/en.msg index 8ec8786..6dcd6e0 100644 --- a/msgs/en.msg +++ b/msgs/en.msg @@ -81,6 +81,7 @@ ::msgcat::mcset en "Indent foreground" ::msgcat::mcset en "Indent background" ::msgcat::mcset en "Interface language" +::msgcat::mcset en "Insert image" ::msgcat::mcset en "Install Tcl/Tk Project Manager" ::msgcat::mcset en "Input file name" ::msgcat::mcset en "Key bindings" @@ -184,3 +185,4 @@ + diff --git a/msgs/ru.msg b/msgs/ru.msg index 61e45d4..5f0c270 100644 --- a/msgs/ru.msg +++ b/msgs/ru.msg @@ -85,6 +85,7 @@ ::msgcat::mcset ru "Indent foreground" "ミ渙セミエムミイミオムひコミー ミセムびムびσソミー" ::msgcat::mcset ru "Indent background" "ミ渙セミエムミイミオムひコミー ミセムびムびσソミー" ::msgcat::mcset ru "Insert" "ミ柘ムひーミイミコミー" +::msgcat::mcset ru "Insert image" "ミ柘ムひーミイミクムび ミクミキミセミアムミーミカミオミスミクミオ" ::msgcat::mcset ru "Interface language" "ミッミキム巾コ ミクミスムひオムムミオミケムミー" ::msgcat::mcset ru "Interpetator" "ミ侑スムひオムミソムミオムひームひセム" ::msgcat::mcset ru "Install Tcl/Tk Project Manager" "ミ」ムムひーミスミセミイミコミー Tcl/Tk Project Manager" @@ -182,3 +183,4 @@ ::msgcat::mcset ru "Was replacement" "ミ帯巾サミセ ミキミーミシミオミスミオミスミセ" ::msgcat::mcset ru "Word wrapping" "ミ渙オムミオミスミセム ムミサミセミイ" ::msgcat::mcset ru "Work dir" "ミミーミアミセムミクミケ ミコミームひーミサミセミウ" + diff --git a/projman.tcl b/projman.tcl index 267c928..ffa5ab6 100755 --- a/projman.tcl +++ b/projman.tcl @@ -15,6 +15,8 @@ set ver "0.4.5" package require BWidget package require msgcat +package require base64 +package require Img set wishOpList [info commands] ## DO NOT EDIT THIS LINE! USE install.tcl SCRIPT ## @@ -172,3 +174,5 @@ option add *Dialog.msg.background $editor(bg) # option add *Text.HighlightThickness 2 userDefault # option add *Entry.HighlightThickness 1 userDefault + +