Project

General

Profile

Statistics
| Branch: | Revision:

root / src / tkenv / treemgr.tcl @ e1750c09

History | View | Annotate | Download (2.76 KB)

1 01873262 Georg Kunz
#=================================================================
2
#  TREEMGR.TCL - part of
3
#
4
#                     OMNeT++/OMNEST
5
#            Discrete System Simulation in C++
6
#
7
#=================================================================
8
9
#----------------------------------------------------------------#
10
#  Copyright (C) 1992-2008 Andras Varga
11
#
12
#  This file is distributed WITHOUT ANY WARRANTY. See the file
13
#  `license' for details on this and other legal matters.
14
#----------------------------------------------------------------#
15
16
17
18
# initTreeManager --
19
#
20
#
21
proc initTreeManager {} {
22
    global widgets
23
    global B2 B3
24
25
    Tree:init $widgets(manager).tree getNodeInfo
26
27
    #
28
    # bindings for the tree
29
    #
30
    bind $widgets(manager).tree <Double-1> {
31
        focus %W
32
        #updateTreeManager
33
        set key [Tree:nodeat %W %x %y]
34
        if {$key!=""} {
35
            # Tree:toggle %W $key
36
            treemanagerDoubleClick $key
37
        }
38
    }
39
40
    bind $widgets(manager).tree <Button-$B3> {
41
        focus %W
42
        #updateTreeManager
43
        set key [Tree:nodeat %W %x %y]
44
        if {$key!=""} {
45
            Tree:setselection %W $key
46
            treemanagerPopup $key %X %Y
47
        }
48
    }
49
}
50
51
52
# updateTreeManager --
53
#
54
# Redraws the manager window (left side of main window).
55
#
56
proc updateTreeManager {} {
57
    global widgets config
58
59
    # spare work if we're not displayed
60
    if {$config(display-treeview)==0} {return}
61
62
    Tree:build $widgets(manager).tree
63
    $widgets(manager).tree xview moveto 0
64
}
65
66
# getNodeInfo --
67
#
68
# This user-supplied function gets called by the tree widget to get info about
69
# tree nodes. The widget itself only stores the state (open/closed) of the
70
# nodes, everything else comes from this function.
71
#
72
# We use the object pointer as tree element key.
73
#
74
proc getNodeInfo {w op {key {}}} {
75
    global icons
76
77
    set ptr $key
78
    switch $op {
79
80
      text {
81
        set id [opp_getobjectid $ptr]
82
        if {$id!=""} {set id " (id=$id)"}
83
        return "[opp_getobjectfullname $ptr] ([opp_getobjectshorttypename $ptr])$id"
84
      }
85
86
      needcheckbox {
87
        return 0
88
      }
89
90
      options {
91
        return ""
92
      }
93
94
      icon {
95
        return [get_icon_for_object $ptr]
96
      }
97
98
      haschildren {
99
        return [opp_haschildobjects $ptr]
100
      }
101
102
      children {
103
        return [opp_getchildobjects $ptr]
104
      }
105
106
      root {
107
        return [opp_object_simulation]
108
      }
109
    }
110
}
111
112
113
#------------------------------
114
# Bindings for the tree manager
115
#------------------------------
116
117
proc treemanagerDoubleClick {key} {
118
    # $key is the object pointer
119
    opp_inspect $key "(default)"
120
}
121
122
proc treemanagerPopup {key x y} {
123
    global ned
124
125
    # $key is the object pointer
126
    set ptr $key
127
    set popup [create_inspector_contextmenu $ptr]
128
    tk_popup $popup $x $y
129
}
130
131