Page 3 of 6
Posted: Sun 01 Sep 2019, 08:14
by stemsee
Hi Fred
I just had an idea. Instead of redirecting to a file, for save on exit, it coud be directed to the pipe which feeds the dual pane, for the purpose of editing/saving. Any thoughts?
stemsee
Posted: Sun 01 Sep 2019, 11:05
by stemsee
Hi Fred
Do you think we could add a delete button in the dual pane saved texts viewer, to deleted selected?
stemsee
Posted: Sun 01 Sep 2019, 11:22
by fredx181
Thanks stemsee !
Since I almost finished new trans_tray with added 'Preferences' to Menu, I added choice to close the window when clicking Save (and then edits will be saved the way you suggested)
Hi Fred
I just had an idea. Instead of redirecting to a file, for save on exit, it coud be directed to the pipe which feeds the dual pane, for the purpose of editing/saving. Any thoughts?
....
....
Do you think we could add a delete button in the dual pane saved texts viewer, to deleted selected?
No idea if possible, if you know how please share, maybe then for later version, for now I've made new trans_tray, coming up next post.
Fred
Posted: Sun 01 Sep 2019, 11:27
by fredx181
Hi All, here's new trans_tray (trans_tray3, attached below), thanks to stemsee for his latest suggestions. Many changes:
- The main translation window stays open now everytime the tray icon is clicked.
(this means you can do multiple translations in same window (and save all))
- Added 'Clear' button to main translation window. (so it can be emptied)
- Added 'Preferences" entry to Menu. (see pic below)
(with choices e.g. 'on-top', confirmation when Exit and more)
- Changed 'Type or paste text to be translated' to a paned dialog.
- All configurations, icons, saved-texts are now in ~/.trans_tray (and temp files in /tmp/trans_tray)
- Changed 'which' to 'busybox which' in the script for to make it work on Fatdog (thanks stemsee)
- Compatible now with yad compiled with gtk3 (previously button text wasn't always displayed correct, using gtk3)
EDIT: @stemsee, didn't do more with geometry saving (still only the main window), btw I found that with paned windows the --geometry option doesn't work properly, specially when using gtk3
EDIT2: Got a report through PM that on Busterpup the 'bing' translator doesnn't work.
Reason is that Busterpup has included older trans version, and the "Install/Upgrade trans" option didn't work properly to upgrade to the newest, so... re-attached with fix for that (using curl now to download/upgrade trans).
At the same time made some other small fixes, icons etc...
(the code for creating the google.svg icon was enormous, made it 10x smaller, so script is only 30kb now)
Fred
Posted: Sun 01 Sep 2019, 12:31
by vovchik
Dear Fred,
Great work. Trans_tray has certainly come a long way in a very short time. And it is very useful and flexible. Thanks!
With kind regards,
vovchik
Posted: Sun 01 Sep 2019, 16:51
by fredx181
Needed a fix, so re-attached here, (see EDIT2):
http://murga-linux.com/puppy/viewtopic. ... 83#1035783
(got report few hours ago through PM about problems on Busterpup, which has old 'trans' included)
@vovchik, thanks !
Fred
Posted: Mon 02 Sep 2019, 07:16
by stemsee
Hi Fred
Can you get this refresh savedtexts list to work properly?
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo $(ls $HOME/.trans_tray/savedtexts/* | tr ' ' '\n') >$ptxts
}; export -f refresh
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
}; export -f savedtranstexts
On my version I have retained yandex, and added Roman - rm as a translation option (for pinyin).
stemsee
Posted: Mon 02 Sep 2019, 08:07
by fredx181
Hi stemsee, this change in function refresh works for me (using the same as is in the list code)
Code: Select all
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
Fred
Posted: Mon 02 Sep 2019, 08:43
by stemsee
yes, i got up too early....i thought about it after posting and realised the same version. In fact I had tried that first but i had two versions of the same script open and edited the wrong one so I didn't see it work...ha ha
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
for f in $HOME/.trans_tray/savedtexts/trans-*_*
do
[[ -f "${f}" ]] && echo "${f##*/}" >$ptxts
done
}; export -f refresh
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
}; export -f savedtranstexts
Also in my version $ONTOP is applied to every windows so all are on-top or none.
Posted: Mon 02 Sep 2019, 09:40
by stemsee
hi Fred
howabout --dclick-action deletes selected saved text.
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
for f in $HOME/.trans_tray/savedtexts/trans-*_*
do
[[ -f "${f}" ]] && echo "${f##*/}" >$ptxts
done
}; export -f refresh
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--dclick-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; rm -f "%s" ; bash -c refresh\"" \
--select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Refresh!gtk-refresh:bash -c refresh" $ONTOP --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
}; export -f savedtranstexts
Posted: Mon 02 Sep 2019, 10:00
by stemsee
here is my version
includes xclip (x64), trans, trans_tray (4)
Posted: Mon 02 Sep 2019, 10:28
by fredx181
Hi stemsee, here's with Delete button (with dclick-action works also, but I thought that this is better):
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Delete!gtk-delete:bash -c delete" --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread
}; export -f savedtranstexts
EDIT: best to add a message if nothing selected in delete function
Fred
Posted: Mon 02 Sep 2019, 20:17
by stemsee
Hi Fred
The button is better. More difficult to accidentally delete needed translations.
Maybe the dclick function could be to open in external editor, or print as pdf.
stemsee
EDIT: maybe you could add to preferences the ability to set a default text editor as variable $TEXTEDITOR. I will hardcode geany for myself, as dclick open in editor.
Posted: Tue 03 Sep 2019, 09:23
by misko_2083
stemsee wrote:Hi Fred
Maybe the dclick function could be to open in external editor,
Or internal
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete
function edit_traslation (){
cd "$HOME/.trans_tray/savedtexts"
cat "$1" | yad --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
if [ $? -eq 0 ]
then
mv /tmp/Trans-Text-tmp "$1"
rm -f /tmp/Trans-Text-tmp
echo -e '\f' >/tmp/TP
cat "$1" >/tmp/TP
echo -e '\n' >/tmp/TP
fi
}; export -f edit_traslation
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--dclick-action="bash -c "edit_traslation "%s""" \
--select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP "" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Delete!gtk-delete:bash -c delete" --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread
}; export -f savedtranstexts
If it's necessary to asign several options to the right click,
you can use the list dialog that opens at mouse pointer (also --on-top) and lists those options.
Make that dialog close when unfocused and it will emulate the context menu, sort of, behaviour.
Edit: here's with the menu.
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete
function menu_action () {
# figure out what was selected
case "$2" in
"edit") cd "$HOME/.trans_tray/savedtexts"
cat "$1" | yad --width=600 --height=400 --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
if [ $? -eq 0 ]
then
mv /tmp/Trans-Text-tmp "$1"
rm -f /tmp/Trans-Text-tmp
echo -e '\f' >/tmp/TP
cat "$1" >/tmp/TP
echo -e '\n' >/tmp/TP
fi
;;
"print") yad --text "Print action activated" --on-top;;
"delete") yad --text "Delete action activated" --on-top;;
esac
}; export -f menu_action
function menu (){
yad --list --width=200 --height=100 --mouse \
--column action --no-headers "edit" "print" "delete" \
--close-on-unfocus --on-top --no-buttons --undecorated \
--select-action="bash -c "menu_action "$1" "%s"""
}; export -f menu
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--dclick-action="bash -c "menu "%s""" \
--select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP "" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Delete!gtk-delete:bash -c delete" --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread
}; export -f savedtranstexts
Note, after a menu/list item is activated, either focus needs to change or the menu/list dialog has to be closed, e.g. with SIGUSR1.
Posted: Tue 03 Sep 2019, 12:15
by stemsee
Thanks misko
that's very useful. I will play with these options for awhile to see what I can come up with.
stem
Posted: Tue 03 Sep 2019, 12:20
by fredx181
Thanks Misko !! We have a lot to choose from now, here's another, inspired by your "internal" code but with Edit button instead of double-click:
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/sel-file
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete
function edit_translation (){
EDIT="$(cat /tmp/trans_tray/sel-file 2> /dev/null)"
[ -z "$EDIT" ] && exit
cd "$HOME/.trans_tray/savedtexts"
cat "$EDIT" | yad --title="Edit: $EDIT" --window-icon=gtk-save --editable --text-info --width=700 --height=540 --wrap --listen --on-top --button="Cancel!gtk-cancel:1" --button="Save!gtk-save:0" > /tmp/trans_tray/Trans-Text-tmp
if [ $? -eq 0 ]
then
mv /tmp/trans_tray/Trans-Text-tmp "$EDIT"
rm -f /tmp/trans_tray/Trans-Text-tmp
echo -e '\f' >/tmp/trans_tray/TP
cat "$EDIT" >/tmp/trans_tray/TP
echo -e '\n' >/tmp/trans_tray/TP
fi
}; export -f edit_translation
trap "rm -f $stxtp $ptxts" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--select-action="bash -c \"echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP \"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
TEXT=" <b>Select an item from the list</b>"
yad --center --text="$TEXT" --window-icon=gtk-save --width=700 --height=540 --button="Edit!gtk-edit:bash -c edit_translation" --button="Delete!gtk-delete:bash -c delete" --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread
}; export -f savedtranstexts
@stemsee which one do you prefer ?
Fred
Posted: Tue 03 Sep 2019, 12:38
by stemsee
Hi Fred
It's a no brainer! The versatility and future possibilities with the list menu opening at mouse is just awesome. If three more buttons are added on the other hand then minimum geometries are imposed.
In fact refresh and delete buttons should be moved to this list menu. Giving back that lovely clean look we started with.
stemsee
EDIT: But edit is already possible in dual pane window. The limited editing possibilities in yad are not worth employing more than already is the case. geany, swriter, wps etc take it to the next level and beyond.
Posted: Tue 03 Sep 2019, 16:28
by fredx181
stemsee wrote:Hi Fred
It's a no brainer! The versatility and future possibilities with the list menu opening at mouse is just awesome. If three more buttons are added on the other hand then minimum geometries are imposed.
In fact refresh and delete buttons should be moved to this list menu. Giving back that lovely clean look we started with.
.
Ok! Would you mind making that ?, so we add it to next version then.
EDIT: Maybe best to put some text on top that says double-click brings up menu.
EDIT: But edit is already possible in dual pane window. The limited editing possibilities in yad are not worth employing more than already is the case. geany, swriter, wps etc take it to the next level and beyond
I may be missing something, which dual pane window you mean ?
Btw, how is Yandex working for you ?, for me it works only sometimes.
EDIT: Tried your sfs version and your use of $ONTOP is a good idea to implement in next version but doesn't work well how you did, this works to set it where needed:
Code: Select all
. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && ONTOP="--on-top"
Fred
Posted: Tue 03 Sep 2019, 20:03
by fredx181
Just experimenting
Using misko's menu option by only select rather than double-clicking it (has small delay to avoid clicking on menu item when accidentally double-clicking (but maybe delay needs to be increased)):
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
rm -f /tmp/trans_tray/sel-file
}; export -f delete
function menu_action () {
# figure out what was selected
case "$2" in
"edit") cd "$HOME/.trans_tray/savedtexts"
cat "$1" | yad --width=600 --height=400 --title="Edit: $1" --editable --text-info --listen --on-top > /tmp/Trans-Text-tmp
if [ $? -eq 0 ]
then
mv /tmp/Trans-Text-tmp "$1"
rm -f /tmp/Trans-Text-tmp
echo -e '\f' >/tmp/trans_tray/TP
cat "$1" >/tmp/trans_tray/TP
echo -e '\n' >/tmp/trans_tray/TP
fi
;;
"print") yad --text "Print action activated" --on-top;;
"delete") yad --text "Delete action activated" --on-top;;
esac
}; export -f menu_action
function menu (){
echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "$1" >/tmp/trans_tray/sel-file; cat "$1" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP
sleep 0.5
yad --title=savedtranstextsmenu --list --width=200 --height=100 --mouse \
--column action --no-headers "edit" "print" "delete" \
--close-on-unfocus --on-top --no-buttons --undecorated \
--select-action="bash -c \"menu_action "$1" "%s"\""
}; export -f menu
trap "rm -f $stxtp $ptxts" EXIT
yad --plug=$$ --tabnum=1 --list --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--select-action="bash -c \"menu "%s"\"" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 --button="Delete!gtk-delete:bash -c delete" --button="Refresh!gtk-refresh:bash -c refresh" --on-top --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal --buttons-layout=spread
}; export -f savedtranstexts
Fred
Posted: Wed 04 Sep 2019, 00:16
by stemsee
fredx181 wrote:
EDIT: Tried your sfs version and your use of $ONTOP is a good idea to implement in next version but doesn't work well how you did, this works to set it where needed:
Code: Select all
. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && ONTOP="--on-top"
Fred
should it be exported?
Code: Select all
. $HOME/.trans_tray/prefs
[ "$ON_TOP" = "TRUE" ] && export ONTOP="--on-top"
I already implemented the list. And made refresh a 2 second loop. Also added echo -e '\f' to preview pane.
Code: Select all
function savedtranstexts (){
rm -f /tmp/trans_tray/TP
stxtp=/tmp/trans_tray/TP
mkfifo -m 755 $stxtp
exec 4<> $stxtp
rm -f /tmp/trans_tray/PT
export ptxts=/tmp/trans_tray/PT
mkfifo -m 755 $ptxts
exec 6<> $ptxts
function refresh (){
[ -f /tmp/trans_tray/fresh ] && exit
[ ! -f /tmp/trans_tray/fresh ] && touch /tmp/trans_tray/fresh
while sleep 2
do
echo -e '\f' >$ptxts
echo "$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done)" >$ptxts
done
}; export -f refresh
function delete (){
rm -f $HOME/.trans_tray/savedtexts/$(cat /tmp/trans_tray/sel-file)
refresh
echo -e '\f' >/tmp/trans_tray/TP
echo -e '\f' >$stxtp
rm -f /tmp/trans_tray/sel-file
}; export -f delete
function menu_action () {
# figure out what was selected
case "$2" in
"edit") cd "$HOME/.trans_tray/savedtexts"
cat "$1" | yad --width=600 --height=400 --title="Edit: $1" --editable --text-info --mouse --listen --on-top > /tmp/Trans-Text-tmp
if [ $? -eq 0 ]
then
mv /tmp/Trans-Text-tmp "$1"
rm -f /tmp/Trans-Text-tmp
echo -e '\f' >/tmp/TP
cat "$1" >/tmp/TP
echo -e '\n' >/tmp/TP
fi
;;
"print") yad --text "Print action activated" --mouse $ONTOP;;
"delete") bash -c delete;;
"refresh") bash -c refresh;;
"ext.editor") cd "$HOME/.trans_tray/savedtexts"
EDITOR=$(yad --window-icon="/tmp/trans_tray/all.svg" $ONTOP --mouse --entry --text="Enter the editor to use e.g. geany")
"$EDITOR" "$1";;
"copy") cd "$HOME/.trans_tray/savedtexts"
yad --window-icon="/tmp/trans_tray/all.svg" $ONTOP --mouse --file --save --text="Copy to location / rename";;
esac
}; export -f menu_action
function menu (){
yad --list --width=200 --height=100 --mouse \
--column action --no-headers "delete" "refresh" "print" "external editor" "copy" "internal edit" \
--close-on-unfocus $ONTOP --no-buttons --undecorated \
--select-action="bash -c "menu_action "$1" "%s"""
}; export -f menu
trap "rm -f $stxtp" EXIT
yad --plug=$$ --tabnum=1 --list --text="Double click raises menu" --item-separator=" " --listen --column="Saved Trans" \
$(for f in $HOME/.trans_tray/savedtexts/trans-*_*; do [[ -f "${f}" ]] && echo "${f##*/}"; done) \
--dclick-action="bash -c "menu "%s""" \
--select-action="bash -c "echo -e '\f' >/tmp/trans_tray/TP ; cd "$HOME/.trans_tray/savedtexts" ; echo "%s" >/tmp/trans_tray/sel-file; cat "%s" >/tmp/trans_tray/TP ; echo -e '\n' >/tmp/trans_tray/TP "" <&6 &
yad --plug=$$ --tabnum=2 --editable --text-info --wrap --listen <&4 &
WINDOWTITLE="Saved-Texts"
yad --center --window-icon=gtk-save --width=700 --height=540 $ONTOP --no-buttons --paned --splitter=180 --key=$$ --title="$WINDOWTITLE" --tab="Selector" --tab="Preview" --orient=horizontal
}; export -f savedtranstexts