buildFileMenu

$canvaseditor buildFileMenu menu
builds file menu on inside given menu

Available only on level 1, i. e. not available when in group editing mode etc.


obj method canvaseditor buildFileMenu menu {
  $menu add cascade -label File -menu [menu $menu.file]
  $menu.file add command -label New -command [list apply {
      self {
        if {
          [llength [$self private undoStack]] == 0 ||
          [tk_messageBox\
              -title "Empty Workspace"\
              -message "Sure?"\
              -type okcancel] eq "ok"
        } then {
          destroy [$self private canvas].info
          $self canvas delete all
          $self initUndoRedo reset
          $self setting filename "" width 400 height 300 background gray95
          $self canvas configure\
            -width [$self setting width]\
            -height [$self setting height]\
            -bg [$self setting background]
          $self zoom original
        }
      }
    } $self]
  $menu.file add separator
  $menu.file add command -label Open -command [list apply [list self {
        if {
          [llength [$self private undoStack]] == 0 ||
          [tk_messageBox\
              -title "Empty Workspace"\
              -message "Sure?"\
              -type okcancel] eq "ok"
        } then {
          set directory [file normalize [file dirname [info script]]]
          set file [tk_getOpenFile\
              -initialdir $directory\
              -title "Load from library"\
              -defaultextension .vectorleaf\
              -filetypes {{Vectorleaf .vectorleaf}}]
          if {$file ne ""} then {
            $self select
            set ch [open $file r]
            set xml [read $ch]
            close $ch
            $self canvas delete all
            $self processXML $xml
            set initUndoRedo reset
            $self private settings filename $file
            #
            variable filename
            set filename([$self private canvas])\
              [file rootname [file tail $file]]
          }
        }
      } [namespace current]] $self]
  $menu.file add command -label Save\
    -command [list apply {
      {self menu} {
        set file [dict get [$self private settings] filename]
        if {$file eq ""} then {
          $menu.file invoke "Save as"
        } else {
          set ch [open $file w]
          puts $ch [$self canvasToXML]
          close $ch
        }
      }
    } $self $menu]
  $menu.file add command -label "Save as"\
    -command [list apply [list self {
        set directory\
          [file normalize [file dirname [info script]]]
        set file [tk_getSaveFile\
            -initialdir $directory\
            -title "Save Selection"\
            -defaultextension .vectorleaf\
            -filetypes {{Vectorleaf .vectorleaf}}]
        if {$file ne ""} then {
          $self private settings filename $file
          set ch [open $file w]
          puts $ch [$self canvasToXML]
          close $ch
          #
          variable filename
          set filename([$self private canvas])\
            [file rootname [file tail $file]]
        }
      } [namespace current]] $self]
  $menu.file add cascade -label Export\
    -menu [menu $menu.file.export -tearoff no] 
  $menu.file.export add command -label Postscript\
    -command [list apply {
      self {
        set file [dict get [$self private settings] filename]
        if {$file eq ""} then {
          set ps [file join [file dirname [info script]] vectorleaf.ps]
        } else {
          set ps [file rootname $file].ps
        }
        $self selected blink off
        $self elements hide
        $self canvas postscript -file $ps\
          -pagewidth [[$self private canvas] cget -width]
        $self elements hide no
        $self selected blink on
      }
    } $self]
  $menu.file.export add command -label PNG\
    -command [list apply {
      self {
        set file [dict get [$self private settings] filename]
        if {$file eq ""} then {
          set file1 [file join [file dirname [info script]] vectorleaf.png]
        } else {
          set file1 [file rootname $file].png
        }
        $self selected blink off
        $self elements hide
        canvasToBitmap [$self private canvas] $file1 [$self canvas cget -bg]
        $self elements hide no
        $self selected blink on
      }
    } $self]
  $menu.file.export add command -label ImageMagick\
    -command [list apply {
      self {
        set file [dict get [$self private settings] filename]
        if {$file eq ""} then {
          set file1 [file join [file dirname [info script]] vectorleaf.mvg]
        } else {
          set file1 [file rootname $file].mvg
        }
        $self selected blink off
        $self elements hide
        set ch [open $file1 w]
        puts $ch [canvasexport mvg [$self private canvas]]
        close $ch
        $self elements hide no
        $self selected blink on
      }
    } $self]
  $menu.file.export add command -label "Scalable Vector Graphics"\
    -command [list apply {
      self {
        set file [dict get [$self private settings] filename]
        if {$file eq ""} then {
          set file1 [file join [file dirname [info script]] vectorleaf.svg]
        } else {
          set file1 [file rootname $file].svg
        }
        $self selected blink off
        $self elements hide
        set ch [open $file1 w]
        puts $ch [canvasexport svg [$self private canvas]]
        close $ch
        $self elements hide no
        $self selected blink on
      }
    } $self]
  $menu.file add separator
  $menu.file add command -label Info\
    -command "$self buildInfoWindow"
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z