TKE  3.6
Advanced code editor for programmers
api::file Namespace Reference

Functions

 all_indices interp pname
 
 current_index interp pname
 
 get_info interp pname file_index attr
 
 add_buffer interp pname name save_command args
 
 add_file interp pname args
 

Function Documentation

§ add_buffer()

api::file::add_buffer   interp pname name save_command args  

Adds a buffer to the browser. The first option is the name of the buffer. The second option is a command to execute once the save is successful. The remaining arguments are the following options:

Definition at line 271 of file api.tcl.

271  proc add_buffer {interp pname name save_command args} {
272 
273  array set opts [list]
274 
275  # If we have an odd number of arguments, we have an error condition
276  if {[expr [llength $args] % 2] == 1} {
277  return -code error [msgcat::mc "Argument list to api::add_file was not an even key/value pair"]
278  }
279 
280  # Get the options
281  array set opts $args
282 
283  # Change out the gutter commands with interpreter versions
284  if {[info exists opts(-gutters)]} {
285  set new_gutters [list]
286  foreach gutter $opts(-gutters) {
287  set new_sym [list]
288  foreach {symname symopts} [lassign $gutter gutter_name] {
289  set new_symopts [list]
290  foreach {symopt symval} $symopts {
291  switch $symopt {
292  "-onenter" -
293  "-onleave" -
294  "-onclick" {
295  lappend new_symopts $symopt "$interp eval $symval"
296  }
297  default {
298  lappend new_symopts $symopt $symval
299  }
300  }
301  }
302  lappend new_sym $symname $new_symopts
303  }
304  lappend new_gutters [list $gutter_name {*}$new_sym]
305  }
306  set opts(-gutters) $new_gutters
307  }
308 
309  # Set the tags
310  if {[info exists opts(-tags)]} {
311  set tag_list [list]
312  foreach tag $opts(-tags) {
313  lappend tag_list "plugin__${pname}__$tag"
314  }
315  set opts(-tags) $tag_list
316  }
317 
318  # If the save command was specified, add the interpreter evaluation
319  if {$save_command ne ""} {
320  set save_command "$interp eval $save_command"
321  }
322 
323  # Finally, add the buffer
324  gui::add_buffer end $name $save_command {*}[array get opts]
325 
326  # Allow the plugin to manipulate the ctext widget
327  set txt [gui::current_txt]
328  $interp alias $txt $txt
329 
330  return $txt
331 
332  }

§ add_file()

api::file::add_file   interp pname args  

Adds a file to the browser. If the first argument does not start with a '-' character, the argument is considered to be the name of a file to add. If no filename is specified, an empty/unnamed file will be added. All other options are considered to be parameters.

-savecommand command

  • Specifies the name of a command to execute after the file is saved.

-lock (0|1)

  • If set to 0, the file will begin in the unlocked state (i.e., the user can edit the file immediately).
  • If set to 1, the file will begin in the locked state (i.e., the user must unlock the file to edit it)

-readonly (0|1)

  • If set to 1, the file will be considered readonly (i.e., the file will be locked indefinitely); otherwise, the file will be able to be edited.

-remember (0|1)

  • If set to 0, the file will not be saved to the user's session file when the application is quit. By default, the file will be remembered and reloaded when the application is reopened.

-sidebar (0|1)

  • If set to 1 (default), the file's directory contents will be included in the sidebar; otherwise, the file's directory components will not be added to the sidebar.

-saveas (0|1)

  • If set to 0 (default), the file will be saved to the current file; otherwise, the file will always force a save as dialog to be displayed when saving.

-buffer (0|1)

  • If set to 0 (default), the file will be added as a normal file; however, if set to 1, the file will be treated as a temporary file that will be automatically deleted when the tab is closed.

-diff (0|1)

  • If set to 0 (default), the file will be added as an editable file; however, if set to 1, the file will be inserted as a difference viewer, allowing the user to view file differences visually within the editor.

-gutters list

  • Creates a gutter in the editor. The contents of list are as follows:
    1 {name {{symbol_name {symbol_tag_options+}}+}}+
    For a list of valid symbol_tag_options, see the options available for tags in a text widget.

-other (0|1)

  • If set to 0 (default), the file will be created in a new tab in the current pane; however, if set to 1, the file will be created in a new tab in the other pane (the other pane will be created if it does not exist).

-tags list

  • A list of plugin bindtag suffixes that will be applied only to this this text widget.

-name filename

  • If this option is specified when the filename is not specified, it will add a new tab to the editor whose name matches the given name. If the user saves the file, the contents will be saved to disk with the given file name. The given filename does not need to exist prior to calling this procedure.

Definition at line 402 of file api.tcl.

402  proc add_file {interp pname args} {
403 
404  set fname ""
405  array set opts [list]
406 
407  # If no filename is given, add a new file to the editor
408  if {([llength $args] > 0) && ([string index [lindex $args 0] 0] ne "-")} {
409 
410  # Peel the filename from the rest of the arguments
411  set args [lassign $args fname]
412 
413  # Check to make sure that the file is safe to add to the editor, and
414  # if it is, create the normalized pathname of the filename.
415  if {[set fname [interpreter::check_file $pname $fname]] eq ""} {
416  return -code error "permission error"
417  }
418 
419  }
420 
421  # If we have an odd number of arguments, we have an error condition
422  if {[expr [llength $args] % 2] == 1} {
423  return -code error [msgcat::mc "Argument list to api::add_file was not an even key/value pair"]
424  }
425 
426  # Get the options
427  array set opts $args
428 
429  # If the -savecommand option was given, wrap it in an interp eval call
430  # so that we don't execute the command in the master interpreter.
431  if {[info exists opts(-savecommand)]} {
432  set opts(-savecommand) "$interp eval $opts(-savecommand)"
433  }
434 
435  # Change out the gutter commands with interpreter versions
436  if {[info exists opts(-gutters)]} {
437  set new_gutters [list]
438  foreach gutter $opts(-gutters) {
439  set new_sym [list]
440  foreach {symname symopts} [lassign $gutter gutter_name] {
441  set new_symopts [list]
442  foreach {symopt symval} $symopts {
443  switch $symopt {
444  "-onenter" -
445  "-onleave" -
446  "-onclick" {
447  lappend new_symopts $symopt "$interp eval $symval"
448  }
449  default {
450  lappend new_symopts $symopt $symval
451  }
452  }
453  }
454  lappend new_sym $symname $new_symopts
455  }
456  lappend new_gutters [list $gutter_name {*}$new_sym]
457  }
458  set opts(-gutters) $new_gutters
459  }
460 
461  # Set the tags
462  if {[info exists opts(-tags)]} {
463  set tag_list [list]
464  foreach tag $opts(-tags) {
465  lappend tag_list "plugin__${pname}__$tag"
466  }
467  set opts(-tags) $tag_list
468  }
469 
470  # Finally, add the new file
471  if {$fname eq ""} {
472  gui::add_new_file end {*}[array get opts]
473  } else {
474  gui::add_file end $fname {*}[array get opts]
475  }
476 
477  # Allow the plugin to manipulate the ctext widget
478  set txt [gui::current_txt]
479  $interp alias $txt $txt
480 
481  return $txt
482 
483  }

§ all_indices()

api::file::all_indices   interp pname  
Returns
Returns a list containing indices for all of the currently opened files.

Definition at line 221 of file api.tcl.

221  proc all_indices {interp pname} {
222 
223  return [files::get_indices fname]
224 
225  }

§ current_index()

api::file::current_index   interp pname  
Returns
Returns the file index of the file being currently edited. If no such file exists, returns a value of -1.

Definition at line 230 of file api.tcl.

230  proc current_index {interp pname} {
231 
232  return [expr {[catch { gui::get_info {} current fileindex } index] ? -1 : $index}]
233 
234  }

§ get_info()

api::file::get_info   interp pname file_index attr  
Returns
Returns the file information at the given file index.
Parameters
file_indexUnique file identifier that is passed to some plugins.
attrFile attribute to retrieve. The following values are valid for this option:
  • fname : Normalized file name
  • mtime : Last mofication timestamp (in seconds)
  • lock : Specifies the current lock status of the file
  • readonly : Specifies if the file is readonly
  • modified : Specifies if the file has been modified since the last save.
  • sb_index : Specifies the index of the file in the sidebar.
  • txt : Specifies the text widget associated with the file
  • current : Returns 1 if the file is the current file being edited
  • vimmode : Returns 1 if the editor is not in edit mode; otherwise, returns 0.
  • lang : Returns the syntax language.

Definition at line 253 of file api.tcl.

253  proc get_info {interp pname file_index attr} {
254 
255  set value [gui::get_file_info $file_index $attr]
256 
257  if {$attr eq "txt"} {
258  interpreter::add_ctext $interp $pname [winfo parent $value]
259  }
260 
261  return $value
262 
263  }