source: tol/tolbase/lib/toltk/listorde.tcl @ 0e07e12

1941-docker-image-to-testdevel
Last change on this file since 0e07e12 was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

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

  • Property mode set to 100644
File size: 4.5 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : listorde.tcl
3# PURPOSE : This file contains a namespace called ListOrder with its
4#           functions. It's for creating a listbox and managing its events.
5#           This widgets consist of a listbox and two buttons for ordering the
6#           items of the listbox. It can also order the items of other
7#           aditional hidden list.
8#/////////////////////////////////////////////////////////////////////////////
9
10
11#/////////////////////////////////////////////////////////////////////////////
12# TESTING
13#/////////////////////////////////////////////////////////////////////////////
14# Put if {1} for testing this file.
15if {0} {
16  package require Tk
17  package require BWidget
18  # force BWidget autoload
19  Bitmap::use
20  set toltk_script_path [file dirname [info script]]
21  set toltk_images_path [file join ${toltk_script_path} images]
22  if { [lsearch $Bitmap::path $toltk_images_path] == -1 } {
23      lappend Bitmap::path [file join $toltk_script_path images]
24  }
25  package require msgcat
26  namespace import msgcat::*
27  ::msgcat::mclocale es
28  ::msgcat::mcload [file join $toltk_script_path msgs]
29}
30
31
32#/////////////////////////////////////////////////////////////////////////////
33  namespace eval ListOrder {
34#
35# PURPOSE: The purpose of this namespace is organize code and functions.
36#
37#/////////////////////////////////////////////////////////////////////////////
38}
39
40
41#/////////////////////////////////////////////////////////////////////////////
42  proc ::ListOrder::Create {w var1 {var2 ""} args} {
43#
44# PURPOSE: Creates a listbox and two button for ordering the items of the
45#          listbox.
46#
47# PARAMETERS:
48#   w    -> widget's path (frame)
49#   var1  -> name of list to order, which is showed at the listbox
50#   var2  -> name of list to order, which is hidden
51#   args -> other args
52#
53#/////////////////////////////////////////////////////////////////////////////
54  frame $w -class ListOrder 
55
56  ScrolledWindow $w.sw
57  listbox $w.sw.lb -selectmode browse -listvariable $var1 -height 6
58  $w.sw setwidget $w.sw.lb
59  bind $w.sw.lb <Button-1> +[list focus -force %W]
60 
61  frame $w.f
62  Button $w.f.bUp -image [Bitmap::get upNext] -height 16 -width 16 \
63    -command [list ::ListOrder::Up $w $var2] -relief link \
64    -helptext [mc "Moves up selected item one position"]
65
66  Button $w.f.bDown -image [Bitmap::get downNext] -height 16 -width 16 \
67    -command [list ::ListOrder::Down $w $var2] -relief link \
68    -helptext [mc "Moves down selected item one position"]
69
70  grid $w.f.bUp   -sticky s -padx 2 -pady 2
71  grid $w.f.bDown -sticky n -padx 2 -pady 2
72
73  grid $w.sw $w.f -sticky news
74  grid columnconfigure $w 0 -weight 1
75  grid rowconfigure    $w 0 -weight 1
76  grid columnconfigure $w 1 -pad 5
77
78}
79
80
81#/////////////////////////////////////////////////////////////////////////////
82  proc ::ListOrder::Up {w {var ""}} {
83#
84# PURPOSE: Moves the item selected in the listbox one position upwards and
85#          sorts the items of a list according the up movement.
86#
87# PARAMETERS:
88#   w   -> listorder widget's path
89#   var -> name of list to order
90#
91#/////////////////////////////////////////////////////////////////////////////
92  upvar \#0 $var list
93  set id [$w.sw.lb curselection]
94  if ![string equal $id ""] {
95    set item [$w.sw.lb get $id]
96    if [expr $id > 0] {
97      $w.sw.lb delete $id
98      $w.sw.lb insert [expr $id - 1] $item
99      $w.sw.lb selection set [expr $id -1]
100      if ![string equal $var ""] {     
101        set itemList [lindex $list $id]
102        set list [lreplace $list $id $id]
103        set list [linsert $list [expr $id -1] $itemList]
104      }
105    }
106  }
107}
108
109
110#/////////////////////////////////////////////////////////////////////////////
111  proc ::ListOrder::Down {w {var ""}} {
112#
113# PURPOSE: Moves the item selected in the listbox one position downwards and
114#          sorts the items of a list according the down movement
115#
116# PARAMETERS:
117#   w   -> listorder widget's path
118#   var -> name of list to order
119#
120#/////////////////////////////////////////////////////////////////////////////
121  upvar \#0 $var list
122  set id [$w.sw.lb curselection]
123  if ![string equal $id ""] {
124    set item [$w.sw.lb get $id]
125    if [expr $id < [expr [$w.sw.lb index end] -1]] {
126      $w.sw.lb delete $id
127      $w.sw.lb insert [expr $id + 1] $item
128      $w.sw.lb selection set [expr $id + 1]
129      if ![string equal $var ""] {
130        set itemList [lindex $list $id]
131        set list [lreplace $list $id $id]
132        set list [linsert $list [expr $id + 1] $itemList]
133      }
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.