summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/tk/lib/tkextlib/tcllib/ctext.rb
blob: 308847c23367f7e7acb814b304af8b1d9425201c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#
#  tkextlib/tcllib/ctext.rb
#                               by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
#   * Part of tcllib extension
#   * Overloads the text widget and provides new commands
#

require 'tk'
require 'tk/text'
require 'tkextlib/tcllib.rb'

# TkPackage.require('ctext', '3.1')
TkPackage.require('ctext')

module Tk
  module Tcllib
    class CText < Tk::Text
      PACKAGE_NAME = 'ctext'.freeze
      def self.package_name
        PACKAGE_NAME
      end

      def self.package_version
        begin
          TkPackage.require('ctext')
        rescue
          ''
        end
      end
    end
  end
end

class Tk::Tcllib::CText
  TkCommandNames = ['ctext'.freeze].freeze
  WidgetClassName = 'Ctext'.freeze
  WidgetClassNames[WidgetClassName] ||= self

  def create_self(keys)
    if keys and keys != None
      tk_call_without_enc(self.class::TkCommandNames[0], @path,
                          *hash_kv(keys, true))
    else
      tk_call_without_enc(self.class::TkCommandNames[0], @path)
    end
  end
  private :create_self

  def __strval_optkeys
    super() << 'linemapfg' << 'linemapbg' <<
      'linemap_select_fg' << 'linemap_select_bg'
  end
  private :__strval_optkeys

  def __boolval_optkeys
    super() << 'highlight' << 'linemap_markable'
  end
  private :__boolval_optkeys

  def append(*args)
    tk_send('append', *args)
  end

  def copy
    tk_send('copy')
  end

  def cut
    tk_send('cut')
  end

  def fast_delete(*args)
    tk_send('fastdelete', *args)
  end

  def fast_insert(*args)
    tk_send('fastinsert', *args)
  end

  def highlight(*args)
    tk_send('highlight', *args)
  end

  def paste
    tk_send('paste')
  end

  def edit(*args)
    tk_send('edit', *args)
  end

  def add_highlight_class(klass, col, *keywords)
    tk_call('ctext::addHighlightClass', @path, klass, col, keywords.flatten)
    self
  end

  def add_highlight_class_for_special_chars(klass, col, *chrs)
    tk_call('ctext::addHighlightClassForSpecialChars',
            @path, klass, col, chrs.join(''))
    self
  end

  def add_highlight_class_for_regexp(klass, col, tcl_regexp)
    tk_call('ctext::addHighlightClassForRegexp',
            @path, klass, col, tcl_regexp)
    self
  end

  def add_highlight_class_with_only_char_start(klass, col, chr)
    tk_call('ctext::addHighlightClassWithOnlyCharStart',
            @path, klass, col, chr)
    self
  end

  def clear_highlight_classes
    tk_call('ctext::clearHighlightClasses', @path)
    self
  end

  def get_highlight_classes
    tk_split_simplelist(tk_call('ctext::getHighlightClasses', @path))
  end

  def delete_highlight_class(klass)
    tk_call('ctext::deleteHighlightClass', @path, klass)
    self
  end

  def enable_C_comments
    tk_call('ctext::enableComments', @path)
    self
  end

  def disable_C_comments
    tk_call('ctext::disableComments', @path)
    self
  end

  def find_next_char(idx, chr)
    tk_call('ctext::findNextChar', @path, idx, chr)
  end

  def find_next_space(idx)
    tk_call('ctext::findNextSpace', @path, idx)
  end

  def find_previous_space(idx)
    tk_call('ctext::findPreviousSpace', @path, idx)
  end

  def set_update_proc(cmd=Proc.new)
    tk_call('proc', 'ctext::update', '', cmd)
    self
  end

  def modified?(mode)
    bool(tk_call('ctext::modified', @path, mode))
  end
end