Changeset 0e07e12 in tol for tolbase/lib/toltk/bystext.tcl


Ignore:
Timestamp:
Feb 15, 2012, 11:55:07 PM (15 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
878425e
Parents:
1efd6f9
Message:

fixes #1432, se implementa una opcion de menu contextual "Escape text" que abre una ventana de dialogo para realizar el escape del texto deseado. Si en el momento de seleccionar esta opción de menú hay un texto seleccionado este se utiliza como texto inicial a escapar. La ventana ofrece un botón para sustituir el texto seleccionado por el texto escapado.

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

File:
1 edited

Legend:

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

    r1efd6f9 r0e07e12  
    88#/////////////////////////////////////////////////////////////////////////////
    99# Put if {1} for testing this file.
     10
     11package require snit
     12
    1013if {0} {
    1114  package require Tk
    … …  
    1922}
    2023
     24::snit::widgetadaptor rotext {
     25
     26  constructor {args} {
     27    # Turn off the insert cursor
     28    #installhull using text $self -insertwidth 0
     29    # DDG the $self gaves an error at least with 0.97 onwards
     30    installhull using text -insertwidth 0
     31   
     32    # Apply an options passed at creation time.
     33    $self configurelist $args
     34  }
     35 
     36  # Disable the insert and delete methods, to make this readonly.
     37  method insert {args} {}
     38  method delete {args} {}
     39 
     40  # Enable ins and del as synonyms, so the program can insert and
     41  # delete.
     42  delegate method ins to hull as insert
     43  delegate method del to hull as delete
     44 
     45  # Pass all other methods and options to the real text widget, so
     46  # that the remaining behavior is as expected.
     47  delegate method * to hull
     48  delegate option * to hull
     49}
    2150
    2251#/////////////////////////////////////////////////////////////////////////////
    … …  
    793822}
    794823
     824proc ::BayesText::TolEscape { buffer } {
     825  return [ string map [ list \n \\n \t \\t \" \\\" \\ \\\\ ] $buffer ]
     826}
     827
     828proc ::BayesText::DlgEscapeTextApply { editor } {
     829  set w .dlgescape
     830
     831  set idxs [ $editor tag ranges sel ]
     832  if { [ llength $idxs ] } {
     833    foreach {i0 i1} $idxs break
     834    $editor configure -undo 0
     835    $editor delete $i0 $i1
     836    $editor configure -undo 1
     837    set f [ $w getframe ]
     838    set buffer [ $f.t get 1.0 "end -1 char" ]
     839    set len [ string length $buffer ]
     840    $editor insert $i0 $buffer
     841    $editor tag add sel $i0 "$i0 + $len char"
     842  }
     843}
     844
     845proc ::BayesText::DlgEscapeText { editor } {
     846  set w .dlgescape
     847  if { [ winfo exists $w ] } {
     848    set f [ $w getframe ]
     849    raise $w
     850    focus $f.o
     851  } else {
     852    Dialog $w -title [ mc "Escape text" ] \
     853        -default 2 -modal none -parent $editor -separator 1
     854    $w add -text [ mc "Close" ] -command "destroy $w"
     855    $w add -text [ mc "Apply" ]
     856    set f [ $w getframe ]
     857    label $f.lo -text [ mc "Original:" ]
     858    text $f.o -width 40 -height 4
     859    label $f.lt -text [ mc "Transformed:" ]
     860    rotext $f.t -width 40 -height 4
     861    bind $f.o <<Modified>> {
     862      if { [ %W edit modified ] == 1 } {
     863        set f [ winfo parent %W ]
     864        set tt $f.t
     865        set buffer [ %W get 1.0 "end -1 char" ]
     866        $tt del 1.0 end
     867        $tt ins end [ ::BayesText::TolEscape $buffer ]
     868        %W edit modified 0
     869      }
     870    }
     871    grid $f.lo -row 0 -column 0 -sticky w
     872    grid $f.o -row 1 -column 0 -sticky snew
     873    grid $f.lt -row 0 -column 1 -sticky w
     874    grid $f.t -row 1 -column 1 -sticky snew
     875    foreach c {0 1} {
     876      grid columnconfigure $f $c -weight 1
     877    }
     878    grid rowconfigure $f 1 -weight 1
     879    $w draw
     880  }
     881  $f.o delete 1.0 end
     882  set idxs [ $editor tag ranges sel ]
     883  if { [ llength $idxs ] } {
     884    $f.o insert end [ $editor get [ lindex $idxs 0 ] [ lindex $idxs 1 ] ]
     885  }
     886  $w itemconfigure 1 -command [ list ::BayesText::DlgEscapeTextApply $editor ]
     887}
    795888
    796889#/////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.