head	1.3;
access;
symbols
	ansi-20040316-freeze:1.1.1.1
	autoconf-20031203:1.2
	autoconf-20031202:1.2
	phong-branch:1.2.0.4
	photonmap-branch:1.2.0.2
	rel-6-1-DP:1.1.1.1
	rel-6-0-2:1.1.1.1
	rel-6-0-1-branch:1.1.1.1.0.4
	hartley-6-0-post:1.1.1.1
	hartley-6-0-pre:1.1.1.1
	rel-6-0-1:1.1.1.1
	rel-6-0:1.1.1.1
	rel-5-4:1.1.1.1
	offsite-5-3-pre:1.1.1.1
	rel-5-3:1.1.1.1
	rel-5-1-branch:1.1.1.1.0.2
	AUTOCONF:1.2.0.6
	windows-6-0-branch:1.1.1.1.0.8
	ansi-6-0-branch:1.1.1.1.0.6
	itcl3-2:1.1.1.1
	scriptics:1.1.1;
locks; strict;
comment	@# @;


1.3
date	2004.03.09.21.07.25;	author morrison;	state dead;
branches;
next	1.2;

1.2
date	2003.03.13.19.05.53;	author jra;	state Exp;
branches
	1.2.6.1;
next	1.1;

1.1
date	2000.12.06.21.35.13;	author bparker;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.12.06.21.35.13;	author bparker;	state Exp;
branches
	1.1.1.1.6.1
	1.1.1.1.8.1;
next	;

1.1.1.1.6.1
date	2004.03.17.07.13.09;	author morrison;	state dead;
branches;
next	;

1.1.1.1.8.1
date	2004.03.15.17.27.20;	author morrison;	state dead;
branches;
next	;

1.2.6.1
date	2004.03.15.14.07.04;	author erikg;	state dead;
branches;
next	;


desc
@@


1.3
log
@libitcl3.2 was moved to libitcl and updated to latest developer cvs (3.3 pre-release)
@
text
@#!/bin/sh
#\
exec wish8.4 "$0"
# ======================================================================
# Simple text editor built with [incr Widgets]
# ----------------------------------------------------------------------
#   AUTHOR:  Michael J. McLennan
#    CLASS:  Object-Oriented Programming with [incr Tcl]
# ======================================================================
package require Iwidgets 4.0

option add *edit.width 5i startupFile
option add *edit.height 4i startupFile
option add *Fileselectiondialog.width 4i startupFile
option add *Fileselectiondialog.height 5i startupFile

# ----------------------------------------------------------------------
set FileWindows 0

# ----------------------------------------------------------------------
#  Dialog boxes
# ----------------------------------------------------------------------
iwidgets::messagedialog .notice -title "itkedit: Notice" \
    -bitmap info -buttonboxpos e -modality application
.notice hide OK
.notice hide Help
.notice buttonconfigure Cancel -text "Dismiss"

iwidgets::messagedialog .confirm -title "itkedit: Confirm" \
    -bitmap questhead -modality application
.confirm hide Help
.confirm buttonconfigure OK -text "Yes"
.confirm buttonconfigure Cancel -text "No"

iwidgets::fileselectiondialog .files -title "itkedit: Files" \
    -childsitepos s -modality application
.files hide Help

set PaneMenu "[.files childsite].panes"
iwidgets::optionmenu $PaneMenu -labeltext "Edit Window:"
pack $PaneMenu -pady 6

# ----------------------------------------------------------------------
# USAGE:  file_load
#
# Initiates the process of loading a new text file for editing.
# Pops up a Fileselectiondialog, allowing the user to select a
# file for editing.  If the user pushes the "load" button, the
# file is loaded.
# ----------------------------------------------------------------------
proc file_load {} {
    global FileName PaneMenu

    .files buttonconfigure OK -text "Load"
    if {[.files activate]} {
        set fname [.files get]
        set cmd {
            set fid [open $fname r]
            set text [read $fid]
            close $fid
        }
        if {[catch $cmd err] != 0} {
            .notice configure -bitmap error \
                -text "Cannot load file \"$fname\":\n$err"
            .notice activate
            return
        }

        set pane [$PaneMenu get]
        set win [.edit childsite $pane]
        clear_text $win
        $win.text insert end $text
        $win.text configure -labeltext "file: $fname"

        set FileName($win) $fname
    }
}

# ----------------------------------------------------------------------
# USAGE:  file_save_as
#
# Initiates the process of saving the current text into a particular
# file.  Pops up a Fileselectiondialog, allowing the user to select
# a file for saving.  If the user pushes the "save" button, the
# file is saved.
# ----------------------------------------------------------------------
proc file_save_as {} {
    global FileName PaneMenu

    .files buttonconfigure OK -text "Save"
    if {[.files activate]} {
        set pane [$PaneMenu get]
        set win [.edit childsite $pane]

        set FileName($win) [.files get]

        file_save $win
    }
}

# ----------------------------------------------------------------------
# USAGE:  file_save <win>
#
# Saves the context of <win> into its associated file.  Does the
# dirty work to finish the file_save_as operation.
# ----------------------------------------------------------------------
proc file_save {win} {
    global FileName FileChanged

    set cmd {
        set fid [open $FileName($win) w]
        puts $fid [$win.text get 1.0 end]
        close $fid
        set FileChanged($win) 0
        $win.text configure -labeltext "file: $FileName($win)"
    }
    if {[catch $cmd err] != 0} {
        .notice configure -bitmap error \
            -text "Cannot save file \"$FileName($win)\":\n$err"
        .notice activate
    }
}

# ----------------------------------------------------------------------
# USAGE:  clear_text ?<win>?
#
# Clears the text area associated with <win>, making sure to save
# any pending changes.  If no <win> is specified, then all text
# areas are cleared.
# ----------------------------------------------------------------------
proc clear_text {{areas ""}} {
    global FileName FileChanged FileWindows

    if {$areas == ""} {
        for {set i 0} {$i < $FileWindows} {incr i} {
            set pane "area #[expr $i+1]"
            lappend areas [.edit childsite $pane]
        }
    }

    foreach win $areas {
        if {$FileChanged($win)} {
            set fname [file tail $FileName($win)]
            .confirm configure -text "File \"$fname\" has changed.\nSave changes?"
            if {[.confirm activate]} {
                file_save $win
            }
        }
        $win.text delete 1.0 end
        set FileChanged($win) 0
    }
}

# ----------------------------------------------------------------------
# USAGE:  split_view
#
# Adds another editing pane to the current editor.
# ----------------------------------------------------------------------
proc split_view {} {
    global FileName FileChanged FileWindows PaneMenu

    set pane "area #[incr FileWindows]"
    .edit add $pane -minimum 100
    $PaneMenu insert end $pane

    set win [.edit childsite $pane]

    set FileName($win) untitled.txt
    set FileChanged($win) 0

    iwidgets::scrolledtext $win.text -wrap none -labeltext "file: $FileName($win)" \
        -hscrollmode none -vscrollmode dynamic -visibleitems 1x1
    pack $win.text -expand yes -fill both

    bind [$win.text component text] <KeyPress> "
        set FileChanged($win) 1
    "
}

frame .mbar -borderwidth 2 -relief raised
pack .mbar -side top -fill x

# ----------------------------------------------------------------------
#  FILE menu
# ----------------------------------------------------------------------
menubutton .mbar.file -text "File" -underline 0 -menu .mbar.file.menu
pack .mbar.file -side left -padx 4

menu .mbar.file.menu
.mbar.file.menu add command -label "Load..." \
    -accelerator "  ^L" -underline 0 -command file_load
bind . <Control-KeyPress-l> { .mbar.file.menu invoke "Load..." }

.mbar.file.menu add command -label "Save As..." \
    -accelerator "  ^S" -underline 0 -command file_save_as
bind . <Control-KeyPress-s> { .mbar.file.menu invoke "Save As..." }

.mbar.file.menu add separator
.mbar.file.menu add command -label "Quit" \
    -accelerator "  ^Q" -underline 0 -command {clear_text; exit}
bind . <Control-KeyPress-q> { .mbar.file.menu invoke Quit }

# ----------------------------------------------------------------------
#  VIEW menu
# ----------------------------------------------------------------------
menubutton .mbar.view -text "View" -underline 0 -menu .mbar.view.menu
pack .mbar.view -side left -padx 4

menu .mbar.view.menu
.mbar.view.menu add command -label "Split" \
    -underline 0 -command split_view

# ----------------------------------------------------------------------
#  Editor
# ----------------------------------------------------------------------
iwidgets::panedwindow .edit -orient horizontal
pack .edit -expand yes -fill both

split_view

wm title . "itkedit"
wm protocol . WM_DELETE_WINDOW { .mbar.file.menu invoke Quit }

after idle {
    update idletasks
    wm minsize . [winfo reqwidth .] [winfo reqheight .]
}


@


1.2
log
@*** empty log message ***
@
text
@@


1.2.6.1
log
@merge from head
@
text
@@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
exec itkwish $0
d10 1
a10 1
package require Iwidgets 2.1
d23 1
a23 1
messagedialog .notice -title "itkedit: Notice" \
d29 1
a29 1
messagedialog .confirm -title "itkedit: Confirm" \
d35 1
a35 1
fileselectiondialog .files -title "itkedit: Files" \
d40 1
a40 1
optionmenu $PaneMenu -labeltext "Edit Window:"
d171 1
a171 1
    scrolledtext $win.text -wrap none -labeltext "file: $FileName($win)" \
d216 1
a216 1
panedwindow .edit -orient horizontal
d228 2
@


1.1.1.1
log
@Import itcl3.2
@
text
@@


1.1.1.1.6.1
log
@sync branch with HEAD
@
text
@@


1.1.1.1.8.1
log
@sync with HEAD -- libitcl3.2 is not in libitcl (v3.3)
@
text
@@

