| Author |
Message |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Sat 10 Nov 2012, 17:40 Post_subject:
How can I make the menubar work with the New button. Solved Sub_title: solved |
|
Hello Everyone,
I have done an editor for Manna, but I have no glue on how to make a new note/file with the New button in the file menubar. Not sure if I need another widget or not.
Any help would be great thanks.
code
| Quote: |
#!/bin/bash
GTKDIALOG=gtkdialog
WORKDIR="/usr/local/Manna"
NOTES_DIR="$WORKDIR/notestxt"
#define special Sans-12 font for Reader
CURRFONTNAME=`cat $HOME/.gtkrc-2.0 | grep font_name | cut -d "=" -f2 | cut -d " " -f2 | sed 's/\"//g'` ##define current user-font
if [ "`cat $HOME/.gtkrc-2.0 | grep font_name | grep Sans`" != "" ] && [ "$CURRFONTNAME" != "Sans" ]; then
FONT_NAME="$CURRFONTNAME"
else
FONT_NAME=""
fi
if [ -f "/usr/local/Manna/xresourcesmarker" ]; then #Iguleder derivatives
echo "Xft.dpi: 78" > $HOME/.Xresources
FONT_SIZE="12"
else
FONT_SIZE="16"
fi
echo "style \"specialsize\"
{
font_name=\"$FONT_NAME Sans $FONT_SIZE\"
}
widget \"*\" style \"specialsize\"
class \"*\" style \"specialsize\"" > "$WORKDIR/gtkrc_size"
export GTK2_RC_FILES="$WORKDIR/gtkrc_size:${HOME}/.gtkrc-2.0"
export TMPDIR=/tmp/notes
mkdir -p "$TMPDIR"
echo "$TMPDIR"/notes
export MAIN_DIALOG='
<window title="Notes" icon-name="Com">
<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-new">
<action>new:file</action>
</menuitem>
<menuitem stock-id="gtk-save">
<action>Save:EDITOR</action>
<action>Save:Saving</action>
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-refresh">
<action>refresh:EDITOR</action>
</menuitem>
<menuitem stock-id="gtk-quit">
<action>exit:Quit</action>
</menuitem>
<label>"_File"</label>
</menu>
<menu label="_Edit" use-underline="true">
<menuitem stock-id="gtk-file" label="Send to Abiword">
<action>abiword '"$TMPDIR"'/notes &</action>
</menuitem>
</menu>
</menubar>
</vbox>
<hbox>
<vbox width-request="140">
<table>
<label>Notes</label>
<variable>ITEM</variable>
<input>'"$WORKDIR/gtkrc_size:${HOME}/.gtkrc-2.0"'</input>
<input>ls '"$NOTES_DIR"'</input>
<action>ln -sf "/usr/local/Manna/notestxt/$ITEM" '"$TMPDIR"'/notes</action>
<action>refresh:EDITOR</action>
</table>
</vbox>
<edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="1">
<variable>EDITOR</variable>
<height>450</height>
<width>500</width>
<input file>'"$TMPDIR"'/notes</input>
<output file>'"$TMPDIR"'/notes</output>
</edit>
</hbox>
</frame>
</window>
'
case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --center --program=MAIN_DIALOG ;;
esac
|
Edited_time_total
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 573
|
Posted: Sat 10 Nov 2012, 19:38 Post_subject:
|
|
Hey Oldyeller.
First of all - that's great you've found the way to control the font in Gtkdialog GUI.
I didn't know how to do it until now, thanks!
As for adding a new note, here's an example (perhaps there are better methods, but I always use something like this).
I made it "stand-alone" for clarity, but I'm sure you can adapt it to your reader easily:
| Code: | #! /bin/bash
export NOTES_DIR="/root/testdir"
add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'` # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}
export -f add_note
export ADD_FILE='
<window title="Add Note" modal="true" icon-name="gtk-add" resizable="false">
<vbox>
<frame Note name:>
<entry>
<variable>NOTENAME</variable>
</entry>
<hbox>
<button ok>
<action>add_note</action>
<action>clear:NOTES_LIST</action>
<action>refresh:NOTES_LIST</action>
<action type="closewindow">NOTENAME</action>
</button>
<button cancel>
<action type="closewindow">NOTENAME</action>
</button>
</hbox>
</frame>
</vbox>
</window>
'
export MAIN='
<window width-request="500" height-request="500">
<vbox>
<table>
<variable>NOTES_LIST</variable>
<input>ls '"$NOTES_DIR"'</input>
</table>
<button>
<label>Create new note</label>
<action>launch:ADD_FILE</action>
</button>
</vbox>
</window>
'
gtkdialog -p MAIN |
Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Sun 11 Nov 2012, 00:05 Post_subject:
|
|
Hi SFR,
As far as the font goes all I did was go through a program that had it and took what I needed for my reader and editor. Works great, except one has to edit the file for a different size.
This works great.
Added refresh for the Table ITEM and the new notes show up when the refresh button is pressed.
So is there a way to delete a note if one no longer wants one?
This is so closer of being a basic word editor for my notes
Cheers
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 573
|
Posted: Sun 11 Nov 2012, 06:33 Post_subject:
|
|
| oldyeller wrote: | So is there a way to delete a note if one no longer wants one?
This is so closer of being a basic word editor for my notes  |
Sure it is, even easier:
| Code: | #! /bin/bash
export NOTES_DIR="/root/testdir"
add_note () {
NOTENAME=`echo "$NOTENAME" | tr '/' '_'` # replace '/' with '_'
[ ${#NOTENAME} -eq 0 ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Empty note name!" 0 0 && return
[ -f "$NOTES_DIR"/"$NOTENAME" ] && Xdialog --timeout 5 --title "Reader Error" --msgbox "Error: Note already exists!" 0 0 && return
touch "$NOTES_DIR"/"$NOTENAME"
}
export -f add_note
export ADD_FILE='
<window title="Add Note" modal="true" icon-name="gtk-add" resizable="false">
<vbox>
<frame Note name:>
<entry>
<variable>NOTENAME</variable>
</entry>
<hbox>
<button ok>
<action>add_note</action>
<action>clear:NOTES_LIST</action>
<action>refresh:NOTES_LIST</action>
<action type="closewindow">NOTENAME</action>
</button>
<button cancel>
<action type="closewindow">NOTENAME</action>
</button>
</hbox>
</frame>
</vbox>
</window>
'
export DEL_FILE='
<window title="Del Note" modal="true" icon-name="gtk-remove" resizable="false">
<vbox>
<text><label>Are you sure you want to delete:</label></text>
<text><input>echo "$NOTES_LIST"</input></text>
<hbox>
<button ok>
<variable>CONFIRM</variable>
<action>rm "$NOTES_DIR"/"$NOTES_LIST"</action>
<action>clear:NOTES_LIST</action>
<action>refresh:NOTES_LIST</action>
<action type="closewindow">CONFIRM</action>
</button>
<button cancel>
<action type="closewindow">CONFIRM</action>
</button>
</hbox>
</vbox>
</window>
'
export MAIN='
<window width-request="500" height-request="500">
<vbox>
<table>
<variable>NOTES_LIST</variable>
<input>ls '"$NOTES_DIR"'</input>
</table>
<hbox>
<button>
<label>Create new note</label>
<action>launch:ADD_FILE</action>
</button>
<button>
<label>Delete note</label>
<action>launch:DEL_FILE</action>
</button>
</hbox>
</vbox>
</window>
'
gtkdialog -p MAIN |
You can rename a note too, just need to be checked if the new note name already exists (like in 'add_note' func).
Keep it up & Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
oldyeller

Joined: 15 Nov 2011 Posts: 499 Location: Mishawaka IN
|
Posted: Sun 11 Nov 2012, 15:10 Post_subject:
|
|
Hi SFR,
This works great!!!
Thanks for all your help so far; may need more later
I keep it as stand alone and just have it in as addnotes script.
works great
Cheers
|
|
Back to top
|
|
 |
|