Simple GtkDialog editor and notetaker

Word processors, spreadsheets, presentations, translation, etc.
Post Reply
Message
Author
svanya
Posts: 15
Joined: Mon 29 Sep 2014, 04:57

Simple GtkDialog editor and notetaker

#1 Post by svanya »

I needed a simple note editor, as I am a poet and do not need rich text, just something I can make quick and rapid poems with.

I had been using:

Code: Select all

#!/bin/sh
#$1
NOTE=""
filename=$(basename "$@")

RESULTS=`Xdialog --fixed-font --wrap --left --stdout --title "$filename" --editbox "$@" 600x600`
EXIT_CODE=$?
EXISTS="FALSE"
ID=""
case $EXIT_CODE in
    0) # All OK. The $RESULTS variable holds everything entered/choosed by the user.
		NOTE="$RESULTS"

	RESULTS2=`Xdialog --stdout --fselect "$@" 480x520`
	EXIT_CODE2=$?
	case $EXIT_CODE2 in
		0)

	echo "$NOTE" > "$RESULTS2" 
	esac
		
esac

exit 0
But was having to make allowances for it not wrapping and having to be religious about click OK every time so I did not miss a note.

So I decided today to upgrade to GTKDialog and made the following.

Be forewarned it is still in the experimental stages, and I think higher minds such as many in this community could clean it up very quickly to prevent overwriting files and accidentily failing to save.

Code: Select all

#!/bin/sh

export currentfile="$@"

FILE1=$(cat "$@")
NOTE=""
filename=$(basename "$@")
FIL1=$(echo $FILE1)

confirm_function(){ 
		Xdialog --title "Are you sure you want to save?" --backtitle "Yes or No?" --yesno "Yes to continue and No to cancel" 0 0
		value=$? 
		echo "the result is: $value"
		if [ "$value" = 0 ];
		then
			if [ "$INPUTFILE" = "" ];
			then
				echo "$EDITOR1" > "$currentfile"
			else
				echo "$EDITOR1" > "$INPUTFILE"
			fi
		else
			echo "Save cancelled"
		fi
}
export -f confirm_function

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window>
	<vbox>
		<hbox>
			<edit wrap-mode="3" use-markup="true" accepts-tab="true">
				<label>LEFT</label>
				<variable>EDITOR1</variable>
				<height>600</height>
				<width>600</width>
				<input file>'"$currentfile"'</input>
			</edit>
		</hbox>
		<vbox>
			<button use-stock="true" label="gtk-close"></button>
			<button use-stock="true" label="gtk-save">
				<action>confirm_function</action>
			</button>
			<hbox width-request="350">
				  <entry accept="file">   
					  <variable>INPUTFILE</variable>
				  </entry>
				  <button tooltip-text="Select a file for saving">   
					  <input file stock="gtk-open"></input>
					  <action type="fileselect">INPUTFILE</action>
					  <action>confirm_function</action>
				 </button>
			</hbox>
		</vbox>
	</vbox>
</window>
'
export MAIN_DIALOG

$GTKDIALOG --program=MAIN_DIALOG 

You then just drop a link into /usr/local/bin and you set the Customize Menu to open any text file script or otherwise very very quickly.

Hope it helps someone.

The first incarnation has done wonders for me when I just needed to have a running clipboard, thrash off some ideas, and even more frequently work on shell scripts.

And I am hoping this second will do so, too.

Ciao all! Thanks for being such a great community.

Also, to create new notes (from a second script), in the same fashion (/usr/local/bin)

you change the first

Code: Select all

export currentfile="$@"
to

Code: Select all

seed=$(date +%Y%m%d%H%M%S)
touch /tmp/"newnoteeditorGTK""$seed"

export currentfile=/tmp/"newnoteeditorGTK""$seed"

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#2 Post by dejan555 »

Interesting, I'll have a look at this when I get time.
I did a little app for myself for taking notes/links/contacts maybe I should share it.
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

User avatar
dejan555
Posts: 2798
Joined: Sun 30 Nov 2008, 11:57
Location: Montenegro
Contact:

#3 Post by dejan555 »

Here's my simple version, if a file isn't specified, or given a name on command line, it creates new file with a $seed timestamp like you posted in a directory specified as $NOTESDIR and uses that to save to.

Code: Select all

#!/bin/sh

export NOTESDIR="$HOME/gtknoteeditor"
[ ! -d "$NOTESDIR" ] && mkdir -p "$NOTESDIR"

if [ "$1" = "" ];then
	seed=$(date +%Y%m%d%H%M%S)
	touch "$NOTESDIR/$seed"
	EDITFILE="$NOTESDIR/$seed"
else
	EDITFILE="$1"
	[ ! -f "$EDITFILE" ] && touch "$EDITFILE"
fi
FNAME=$(basename "$EDITFILE")

export NOTE_EDIT='<window title="Note Editor - '"$FNAME"'" width-request="600" height-request="600"><vbox>
<edit wrap-mode="3" use-markup="true" accepts-tab="true">
<variable>NOTE</variable>
<input file>'"$EDITFILE"'</input>
</edit>
<hbox>
<button><label>"Open dir"</label><input file stock="gtk-open"></input>
<action>exec rox "$NOTESDIR"</action>
</button>
<button><label>"Save & Exit"</label><input file stock="gtk-save"></input>
<action>echo "$NOTE" > '"$EDITFILE"'</action>
<action>exit:Save</action>
</button>
<button cancel></button></hbox>
</vbox></window>'

gtkdialog --program=NOTE_EDIT --center
EDIT: Also, see this app:
http://www.murga-linux.com/puppy/viewtopic.php?t=95878
puppy.b0x.me stuff mirrored [url=https://drive.google.com/open?id=0B_Mb589v0iCXNnhSZWRwd3R2UWs]HERE[/url] or [url=http://archive.org/details/Puppy_Linux_puppy.b0x.me_mirror]HERE[/url]

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#4 Post by oldyeller »

Hi svanya,

Download this editor and look at the code and take out what will work for you and let me know how things go. http://www.murga-linux.com/puppy/viewtopic.php?t=85573

Cheers

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#5 Post by slavvo67 »

Hi guys:

The problem with the saved item is that when you go to open it, it defaults to Geany or whatever your default text editor is.

Oldyeller is probably right. He's spent a lot of time on his Manna product so if he's offering some code, it's probably a great base to work off of.

Best,

Slavvo67

Post Reply