| 1 | package require BWidget |
|---|
| 2 | package require snit |
|---|
| 3 | package require mimetex |
|---|
| 4 | package require notebookdb |
|---|
| 5 | package require trycatch |
|---|
| 6 | |
|---|
| 7 | #(pgea) Se utilizará trycatch sin importar sus métodos |
|---|
| 8 | #(pgea) para hacer el código compatible con tcl8.6 |
|---|
| 9 | #(pgea) Por ejemplo: ::trycatch::try ... |
|---|
| 10 | # if { [ info commands "try" ] eq "" } { |
|---|
| 11 | # namespace import ::trycatch::* |
|---|
| 12 | # } |
|---|
| 13 | |
|---|
| 14 | snit::type nbdbmanagerType { |
|---|
| 15 | |
|---|
| 16 | #------------------------------------------------------------------- |
|---|
| 17 | # Instance Variables |
|---|
| 18 | |
|---|
| 19 | # This is an array, indexed by normalized notebook filename. |
|---|
| 20 | # The elements are lists: db <notebookdb> ref <refcount> |
|---|
| 21 | variable registry |
|---|
| 22 | |
|---|
| 23 | method create { name } { |
|---|
| 24 | # FIRST, put the file name into canonical form as an index key. |
|---|
| 25 | set canonicalName [file normalize $name] |
|---|
| 26 | |
|---|
| 27 | # NEXT, do we have a notebookdb for this name? |
|---|
| 28 | if {[info exists registry($canonicalName)]} { |
|---|
| 29 | |
|---|
| 30 | # We do. Increment its reference count. |
|---|
| 31 | array set data $registry($canonicalName) |
|---|
| 32 | incr data(ref) |
|---|
| 33 | set registry($canonicalName) [array get data] |
|---|
| 34 | |
|---|
| 35 | # Return the object. |
|---|
| 36 | return $data(db) |
|---|
| 37 | } |
|---|
| 38 | # NEXT, try to open a file with this name. It might fail with |
|---|
| 39 | # an error, which we won't bother catching; we'd just need to |
|---|
| 40 | # rethrow it. |
|---|
| 41 | set data(db) [ ::notebookdb::notebookdb create %AUTO% -dbfile $name ] |
|---|
| 42 | |
|---|
| 43 | # NEXT, it succeeded. Add it to the registry with a reference |
|---|
| 44 | # count of 1. |
|---|
| 45 | set data(ref) 1 |
|---|
| 46 | set registry($canonicalName) [array get data] |
|---|
| 47 | |
|---|
| 48 | # NEXT, define the Notebook Commands and the required pages |
|---|
| 49 | $self InitializeCommands $data(db) |
|---|
| 50 | |
|---|
| 51 | # FINALLY, return the new notebookdb. |
|---|
| 52 | return $data(db) |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | method InitializeCommands { db } { |
|---|
| 56 | # FIRST, define a private namespace for Notebook's use |
|---|
| 57 | $db eval "namespace eval ::__notebook:: { }" |
|---|
| 58 | |
|---|
| 59 | # FIRST, alias "kernel" commands defined elsewhere in the |
|---|
| 60 | # application. |
|---|
| 61 | $db alias parse ::markupparser::parse |
|---|
| 62 | $db alias image image |
|---|
| 63 | $db alias GetImage Bitmap::get |
|---|
| 64 | $db alias mimetexRender mimetex::RenderImage |
|---|
| 65 | $db eval { |
|---|
| 66 | ::db::PageExpander evalcmd escapemime |
|---|
| 67 | ::db::PageExpander errmode error |
|---|
| 68 | |
|---|
| 69 | proc escapemime { macro } { |
|---|
| 70 | #puts "escapeeval = '$macro'" |
|---|
| 71 | if { [ string range [ string trimleft $macro ] 0 6 ] eq "mimetex" } { |
|---|
| 72 | set latex [ string range $macro 7 end ] |
|---|
| 73 | return [ mimetex $latex ] |
|---|
| 74 | } else { |
|---|
| 75 | eval $macro |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | proc img { imageORfile } { |
|---|
| 80 | if { [ lsearch [ image names ] $imageORfile ] == -1 } { |
|---|
| 81 | set img [ GetImage $imageORfile ] |
|---|
| 82 | } else { |
|---|
| 83 | set img $imageORfile |
|---|
| 84 | } |
|---|
| 85 | return "\[!image $img !\]" |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | proc mimetex { latex } { |
|---|
| 89 | set img [ mimetexRender $latex ] |
|---|
| 90 | return "\[!image $img !\]" |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | array set urlConf { |
|---|
| 94 | tol,root https://www.tol-project.org |
|---|
| 95 | tol,wiki https://www.tol-project.org/wiki |
|---|
| 96 | tol,milestone https://www.tol-project.org/milestone |
|---|
| 97 | tol,ticket https://www.tol-project.org/ticket |
|---|
| 98 | mms,root https://trac.localbayes.es/mms |
|---|
| 99 | mms,wiki https://trac.localbayes.es/mms/wiki |
|---|
| 100 | mms,milestone https://www.tol-project.org/mms/milestone |
|---|
| 101 | mms,ticket https://www.tol-project.org/mms/ticket |
|---|
| 102 | tol,browser https://www.tol-project.org/browser/tolp |
|---|
| 103 | tol,browser,default trunk |
|---|
| 104 | mms,browser https://trac.localbayes.es/mms/browser |
|---|
| 105 | mms,browser,default trunk |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | # [@url mms howto/5 "HOWTO 5" wiki @] |
|---|
| 109 | # [@url mms howto/5 "HOWTO 5" @] |
|---|
| 110 | # [@url mms howto/5 @] |
|---|
| 111 | proc url { where path args } { |
|---|
| 112 | foreach { label section } {"" ""} break |
|---|
| 113 | foreach { label section } $args break |
|---|
| 114 | if { $section eq "" } { |
|---|
| 115 | set section "wiki" |
|---|
| 116 | } |
|---|
| 117 | set urlroot $::urlConf(${where},root) |
|---|
| 118 | set url "$::urlConf(${where},root)/$section/$path" |
|---|
| 119 | if { $label eq "" } { |
|---|
| 120 | return "\[${url}\]" |
|---|
| 121 | } else { |
|---|
| 122 | return "\[$label | ${url}\]" |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | # [@mms howto/5 "HOWTO 5" wiki @] |
|---|
| 127 | # [@mms howto/5 "HOWTO 5" @] |
|---|
| 128 | # [@mms howto/5 @] |
|---|
| 129 | proc mms { path args } { |
|---|
| 130 | return [ eval url mms $path $args ] |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | proc tol { path args } { |
|---|
| 134 | return [ eval url tol $path $args ] |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | # [@src tol tol/init.cpp init.cpp trunk@] |
|---|
| 138 | # [@src tol tol/init.cpp init.cpp@] |
|---|
| 139 | # [@src tol tol/init.cpp@] |
|---|
| 140 | # [@src mms MMS/definition/01_variable/def_variable.tol def_variable.tol@] |
|---|
| 141 | proc src { where path args } { |
|---|
| 142 | foreach { label release } {"" ""} break |
|---|
| 143 | foreach { label release } $args break |
|---|
| 144 | if { $release eq "" } { |
|---|
| 145 | set release "trunk" |
|---|
| 146 | } |
|---|
| 147 | set urlroot $::urlConf(${where},browser) |
|---|
| 148 | set url "${urlroot}/${release}/${path}" |
|---|
| 149 | if { $label eq "" } { |
|---|
| 150 | return "\[${url}\]" |
|---|
| 151 | } else { |
|---|
| 152 | return "\[$label | ${url}\]" |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | package provide nbdbmanager 1.0 |
|---|