Changeset 00c4270 in tol


Ignore:
Timestamp:
Dec 15, 2011, 9:37:54 AM (15 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
2d896ea
Parents:
0da9dfe
Message:

refs #1191, implementing contextual menu ...

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3928 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tolbase/lib/toltk/tolpkg_gui.tcl

    r0da9dfe r00c4270  
    11package require wtree
    22package require BWidget
     3package require msgcat
    34
    45namespace eval ::TolPkgGUI {
    56
     7  namespace import ::msgcat::*
     8
    69  variable widgets
    710
    … …  
    912
    1013  variable urlmap
    11   variable localInfo
     14 
     15  variable localPackageInfo
     16  variable localVersionInfo
     17  variable nodesInfo
     18
    1219  variable localSortedNames
    1320  variable treeParents
    … …  
    645652                         [ array names localInfo ] ]
    646653  }
    647   array set treeParents {}
     654  array unset treeParents
    648655  foreach n $localNames {
    649656    array set pkg $localInfo($n)
    … …  
    672679  variable localVersionInfo
    673680  variable treeParents
     681  variable nodesInfo
    674682
    675683  $T configure -table no -filter yes -columns {
    … …  
    680688    array set localPackageInfo $p
    681689  }
    682   array set treeParents {}
     690  array unset treeParents
     691  array unset nodesInfo
    683692  # insert package information
    684693  foreach p [ array names localPackageInfo ] {
    … …  
    691700                                        -at end -relative root \
    692701                                        -button auto ]
     702        set nodesInfo($treeParents($pkgRepo),type) repo
    693703      }
    694704      set lastremote $pkg(lastremote)
    … …  
    696706      if { $lastlocal eq "" } {
    697707        set img "package_down_16"
     708        set nodeStatus new
    698709      } else {
    699710        set idx [ SortVersion $lastremote $lastlocal ]
    700         set img [ lindex { cdr_tick_16 software_update_16 } $idx ]
     711        if { $idx <= 0 } {
     712          # could be -1 (because of date error)
     713          set img "cdr_tick_16"
     714          set nodeStatus ok
     715        } else {
     716          set img "software_update_16"
     717          set nodeStatus upgrade
     718        }
    701719      }
    702720      set treeParents($p) [ $T insert [ list [ list $img $p ] ] \
    703721                                -at end -relative $treeParents($pkgRepo) \
    704722                                -button auto ]
     723      set nodesInfo($treeParents($p),type) pkg
     724      set nodesInfo($treeParents($p),status) $nodeStatus
    705725    }
    706726  }
    … …  
    723743        set treeParents($pkgRepo) [ $T insert [ list [ list database_1_16 $pkgRepo ] ] \
    724744                                        -at end -relative root -button auto ]
     745        set nodesInfo($treeParents($pkgRepo),type) repo
    725746      }
    726747      set treeParents($pkgRoot) [ $T insert [ list [ list {} $pkgRoot ] ] \
    727748                                      -at end -relative $treeParents($pkgRepo) \
    728749                                      -button auto ]
     750      set nodesInfo($treeParents($pkgRoot),type) pkg
    729751    }
    730752    set dateremote $pkg(dateremote)
    … …  
    732754    if { $datelocal eq "TheBegin" } {
    733755      set img "package_down_16"
     756      set nodesStatus new
    734757    } else {
    735758      set idx [ string compare $dateremote $datelocal ]
    736       if { $idx == -1 } {
     759      if { $idx <= 0 } {
     760        # could be -1 (because of date error)
    737761        set img "cdr_tick_16"
     762        set nodeStatus ok
    738763      } else {
    739         set img [ lindex { cdr_tick_16 software_update_16 } $idx ]
     764        set img "software_update_16"
     765        set nodeStatus update
    740766      }
    741767    }
    742768    set nid [ $T insert [ list [ list $img $pv ] ] \
    743769                  -at end -relative $treeParents($pkgRoot) -button auto ]
     770    set nodesInfo($nid,type) pkgver
     771    set nodesInfo($nid,status) $nodeStatus
    744772    foreach d $pkg(dependencies) {
    745       $T insert [ list [ list back_to_ou_16 $d ] ] \
    746                   -at end -relative $nid -button no
     773      set nid [ $T insert [ list [ list back_to_ou_16 $d ] ] \
     774                    -at end -relative $nid -button no ]
     775      set nodesInfo($nid,type) pkgdep
    747776    }
    748777  }
    … …  
    845874  CreateToolBar $t
    846875
     876  if { 0 } {
    847877  AddToolButton $t refresh \
    848878      -image database_refresh_32 -text  [ msgcat::mc "Refresh" ] -compound top \
    … …  
    857887  AddToolButton $t installzip \
    858888      -image install_zip_32 -text [ msgcat::mc "Install Zip" ] -compound top
     889  }
    859890
    860891  CreateTree $t
    861892
    862893  FillTreeInfo [ GetTree $t ]
     894  set T [ GetTree $t ]
     895  menu $T.cmenu -tearoff 0 \
     896      -postcommand [ list ::TolPkgGUI::PostContextMenu $T $T.cmenu ]
     897  $T configure -contextmenu $T.cmenu
     898}
     899
     900proc ::TolPkgGUI::PostContextMenu { T w } {
     901  variable nodesInfo
     902
     903  $w delete 0 end
     904  array set selectionInfo {
     905    repo   ""
     906    pkg    ""
     907    pkgver ""
     908  }
     909  foreach nid [ $T selection get ] {
     910    lappend selectionInfo($nodesInfo($nid,type)) $nid
     911  }
     912  $w add command  -label "[ mc {Add New} ]..." \
     913      -command ::TolPkgGUI::AddNewRepository
     914  set lenRepo [ llength $selectionInfo(repo) ]
     915  if { $lenRepo } {
     916    $w add cascade  -label "[ mc {Check Repository} ]" \
     917        -menu $w.check
     918    if { [ winfo exists $w.check ] } {
     919      $w.check delete 0 end
     920    } else {
     921      menu $w.check -tearoff 0
     922    }
     923    if { $lenRepo > 1 } {
     924      set labelCheck [ mc "Selected" ]
     925    } else {
     926      set labelCheck [ $T item text [ lindex $selectionInfo(repo) 0 ] 0 ]
     927    }
     928    $w.check add command -label $labelCheck \
     929        -command "::TolPkgGUI::CheckRepository $labelCheck $lenRepo"
     930    $w.check add command -label [ mc "All" ] \
     931        -command "::TolPkgGUI::CheckRepository ALL -1"
     932  }
     933  $w add command -label [ mc "Sync with servers" ] \
     934      -command "::TolPkgGUI::SyncServers"
     935  $w add separator
     936  set lenPkg    [ llength $selectionInfo(pkg) ]
     937  set lenPkgVer [ llength $selectionInfo(pkgver) ]
     938  set lenPkgAll [ expr { $lenPkg + $lenPkgVer } ]
     939  if { $lenPkgAll } {
     940    if { $lenPkgAll == 1 } {
     941      if { $lenPkg } {
     942        # process a single node pkg
     943        set nid [ lindex $selectionInfo(pkg) 0 ]
     944        set pkg [ $T item text $nid 0 ]
     945        set status $nodesInfo($nid,status)
     946        if { $status eq "new" } {
     947          $w add command -label [ mc "Install %s" $pkg ] \
     948              -command "::TolPkgGUI::InstallPackage $pkg"
     949        } elseif { $status eq "upgrade" } {
     950          $w add command -label [ mc "Upgrade %s" $pkg ] \
     951              -command "::TolPkgGUI::UpgradePackage $pkg"
     952          $w add command -label [ mc "Upgrade all" ] \
     953              -command "::TolPkgGUI::UpgradePackage"
     954        } elseif { $status ne "ok" } {
     955          puts "unexpected status $status for pkg $pkg"
     956        }
     957      } else {
     958        # process a single node pkgver
     959        set nid [ lindex $selectionInfo(pkgver) 0 ]
     960        set pkgver [ $T item text $nid 0 ]
     961        puts "process a single node pkgver $pkgver"
     962        set status $nodesInfo($nid,status)
     963        if { $status eq "new" } {
     964          $w add command -label [ mc "Install %s" $pkgver ] \
     965              -command "::TolPkgGUI::InstallPackage $pkgver"
     966        } elseif { $status eq "update" } {
     967          $w add command -label [ mc "Update version %s" $pkgver ] \
     968              -command "::TolPkgGUI::UpdatePackageVersion $pkgver"
     969          $w add command -label [ mc "Update all" ] \
     970              -command "::TolPkgGUI::UpdatePackageVersion"
     971        } elseif { $status ne "ok" } {
     972          puts "unexpected status $status for pkgver $pkgver"
     973        }
     974      }
     975    } else {
     976      # there is a multiple selection of pkg and pkgver
     977    }
     978  } else {
     979    # there is no pkg nor pkgver selected
     980  }
     981  $w add command -label "[ mc {Install ZIP} ]..." \
     982      -command "::TolPkgGUI::InstallZip"
     983  $w add separator
     984  # export options
     985 
     986  set selection [$T selection get]
     987  set has_selection [ llength $selection ]
     988  puts "selction = $selection"
     989  puts [ $T item text [ lindex $selection 0 ] 0 ]
     990  return
     991  $w add command -label [ mc "Update" ] \
     992      -command ::TolPkgGUI::Update
     993  $w add command -label [ mc "" ] \
     994      -command ::TolPkgGUI::Update
     995
     996}
     997
     998proc ::TolPkgGUI::AddNewRepository { } {
     999}
     1000
     1001proc ::TolPkgGUI::CheckRepository { repo length } {
     1002}
     1003
     1004proc ::TolPkgGUI::SyncServers { } {
     1005}
     1006
     1007proc ::TolPkgGUI::InstallPackage { p } {
     1008}
     1009
     1010proc ::TolPkgGUI::UpgradePackage { {p ""} } {
     1011}
     1012
     1013proc ::TolPkgGUI::UpdatePackageVersion { {p ""} } {
     1014}
     1015
     1016proc ::TolPkgGUI::InstallZip { } {
    8631017}
    8641018
Note: See TracChangeset for help on using the changeset viewer.