How can I make the menubar work with the New button. Solved

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

How can I make the menubar work with the New button. Solved

#1 Post by oldyeller »

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

#!/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
Last edited by oldyeller on Sun 11 Nov 2012, 19:38, edited 1 time in total.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

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: Select all

#! /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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#3 Post by oldyeller »

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 :D :D

Cheers

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post by SFR »

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 :D :D
Sure it is, even easier:

Code: Select all

#! /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!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

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

#5 Post by oldyeller »

Hi SFR,

This works great!!!

Thanks for all your help so far; may need more later :lol: :lol:

I keep it as stand alone and just have it in as addnotes script.

works great

Cheers

Post Reply