glimmer-dsl-tk 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33884eabc43f9c6b019d12a45f75e19212e2969d447f743e29e9db5cf81c615b
4
- data.tar.gz: 0f0e3558279a70b03aaaf3e7733125eee5bfb5cce320ea34a6bc838803227755
3
+ metadata.gz: 69e1f06607f60b2864e78e6e1eb9bfde7cf98f8d8eca2d14f12bf218d781dcb3
4
+ data.tar.gz: 7c552bb85c6b87eeefe8117b5f3d2df922ff27618f564e6dd37df63b57c17d98
5
5
  SHA512:
6
- metadata.gz: f9dac142530aa07249e92dc4cc314a028f7652582562031b415eaab33ac5c0a1207ef2d4f7bbe330bf62715d78f71727a3ef9f26eb761e52efdcc03778a39ac7
7
- data.tar.gz: 117a6cd4b7fd8472c87b8e4817097d3b6f1c0ff1f765c8fa851b239fff453bbcc2bc7dc69a800d1c9fbee6669b87f821f2d2fa8cef4a407b59c1607c582a0aaf
6
+ metadata.gz: a6dad9353a12a78f0e8c4a2be45e440c2bebb3e0998957447332d0ab65ec3668eb447395cb32bb8bfa4c6feed3bee991d78b07dbe500c3716e914ed0e51b312c
7
+ data.tar.gz: 36bfc6aa1b337b33b6c6a658549b603658677ea0e4e1840ec1ef58727bb12c76031d08b22fd50960001c2881819e7ec1a7e672f1c29e57d63797d0ea106531f0
data/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.34
4
+
5
+ - When applying a `text` selection format without having a selection, have it apply to current insert mark word
6
+ - Support registering multiple general event listeners on `text` widget (previously, later event listener registrations replaced former ones)
7
+ - Implement `:no_selection_default` option of `:insert_word`, `insert_letter`, or `none` for `text` selection formatting methods (`add_selection_format`, `remove_selection_format`, `toggle_selection_format`, `add_selection_font_format`, `remove_selection_font_format`, `toggle_selection_font_format`)
8
+ - Make sure to only allow `text` undo/redo when there are changes to be undoed/redoed
9
+ - Fix issue with Hello, Text! Find Dialog not coming up with keyboard shortcut (e.g. CMD+F) anymore
10
+ - Fix issue with Hello, Text! whereby after applying background, and foreground to a selection, you cannot apply bold, italic, or underline for the same selection (or font-size or font-family)
11
+
3
12
  ## 0.0.33
4
13
 
5
- - Support `text` widget `InsertMarkMoved` listener event to track insert mark movement (or alises `InsertMarkMove`, `insert_mark_move`, `insert_mark_moved`, all case-insensitive)
14
+ - Support `text` widget `InsertMarkMoved` listener event to track insert mark movement (or aliases `InsertMarkMove`, `insert_mark_move`, `insert_mark_moved`, all case-insensitive)
6
15
  - Support `entry` widget `changed` and `modified` listener event aliases for `change` event
7
16
  - Autodiscover format options when moving cursor in `text` widget (auto-derive from applied tags and widget font) and show in top Hello, Text! toolbar comboboxes and buttons
8
17
  - Fix issue with encountering error 'NoMethodError: undefined method "size" for' when launching Hello, Text!, performing Select-All (CMD+A or CONTROL+A) and then attempting to Bold all the text.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.33
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Tk 0.0.34
2
2
  ## MRI Ruby Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-tk.svg)](http://badge.fury.io/rb/glimmer-dsl-tk)
4
4
  [![Ruby](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml/badge.svg)](https://github.com/AndyObtiva/glimmer-dsl-tk/actions/workflows/ruby.yml)
@@ -158,7 +158,7 @@ gem install glimmer-dsl-tk
158
158
 
159
159
  Add the following to `Gemfile`:
160
160
  ```
161
- gem 'glimmer-dsl-tk', '~> 0.0.33'
161
+ gem 'glimmer-dsl-tk', '~> 0.0.34'
162
162
  ```
163
163
 
164
164
  And, then run:
@@ -349,15 +349,20 @@ The `text` widget is enhanced by [Glimmer DSL for Tk](https://rubygems.org/gems/
349
349
  - `add_font_format(region_start, region_end, font_option, value)`
350
350
  - `remove_font_format(region_start, region_end, font_option, value)`
351
351
  - `toggle_font_format(region_start, region_end, font_option, value)`
352
- - `add_selection_format(region_start, region_end, option, value)`
353
- - `remove_selection_format(region_start, region_end, option, value)`
354
- - `toggle_selection_format(region_start, region_end, option, value)`
355
- - `add_selection_font_format(region_start, region_end, font_option, value)`
356
- - `remove_selection_font_format(region_start, region_end, font_option, value)`
357
- - `toggle_selection_font_format(region_start, region_end, font_option, value)`
352
+ - `add_selection_format(option, value, no_selection_default: :insert_word)`: adds format to selection. If there is no selection, then applies format to current insert mark word.
353
+ - `remove_selection_format(option, value, no_selection_default: :insert_word)`
354
+ - `toggle_selection_format(option, value, no_selection_default: :insert_word)`: toggles format on selection. If there is no selection, then toggles format on current insert mark word.
355
+ - `add_selection_font_format(font_option, value, no_selection_default: :insert_word)`
356
+ - `remove_selection_font_format(font_option, value, no_selection_default: :insert_word)`
357
+ - `toggle_selection_font_format(font_option, value, no_selection_default: :insert_word)`
358
358
  - `text#insert_image(text_index, *image_args)`: inserts image into `text` `value` content at `text_index` location (e.g. `'insert'`)
359
359
  - `text#get_open_file_to_insert_image(text_index = 'insert')`: opens a file dialog to select one of the available image formats and then inserts image into `text` `value` content
360
360
 
361
+ The `:no_selection_default` keyword arg to `*_selection_*` methods determines what region to cover when no explicit selection is set:
362
+ - `:insert_word`: current word for insert mark
363
+ - `:insert_letter`: current letter for insert mark
364
+ - `:none`: no behavior when no selection is in place
365
+
361
366
  Available options:
362
367
 
363
368
  - `background`
@@ -731,6 +736,7 @@ More details can be found in the [Hello, Button!](#hello-button) sample below.
731
736
  ## Gotchas
732
737
 
733
738
  - Setting `background` attribute on `frame` or `label` does not work in `'aqua'` theme on the Mac (only in `'classic'` theme)
739
+ - `text` widget does not track `KeyPress`/`KeyRelease` events perfectly (installed via `on()` listener keyword). It seems that when all text is deleted, it stops tracking key presses/releases until a number of new lines have been added to `text` `value` attribute
734
740
 
735
741
  ## Samples
736
742
 
@@ -1869,7 +1875,7 @@ Glimmer app:
1869
1875
 
1870
1876
  ### Hello, Text!
1871
1877
 
1872
- You may use the META+F shortcut to bring up the Find Dialog.
1878
+ You may press META+F to bring up the Find Dialog on the Mac and CONTROL+F to bring it up on Windows/Linux.
1873
1879
 
1874
1880
  Icons used in this sample were made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>
1875
1881
 
@@ -1921,7 +1927,7 @@ class HelloText
1921
1927
  MULTI_LINE_STRING
1922
1928
  end
1923
1929
 
1924
- attr_accessor :document
1930
+ attr_accessor :document, :find_text
1925
1931
 
1926
1932
  attr_accessor :foreground
1927
1933
 
@@ -1947,8 +1953,16 @@ class HelloText
1947
1953
  [FONT_SIZE_PROMPT] + (9..64).to_a.map(&:to_s)
1948
1954
  end
1949
1955
 
1956
+ def find
1957
+ text_index = @text.search(/#{find_text}/i, @text.tag_ranges('sel')&.first&.last || @text.index('insert'))
1958
+ unless text_index.to_s.empty?
1959
+ @text.tag_remove('sel', '1.0', 'end')
1960
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
1961
+ end
1962
+ end
1963
+
1950
1964
  def launch
1951
- root {
1965
+ @root = root {
1952
1966
  title 'Hello, Text!'
1953
1967
  width 1280
1954
1968
  height 800
@@ -1956,11 +1970,6 @@ class HelloText
1956
1970
  frame {
1957
1971
  grid row: 0, column: 0
1958
1972
 
1959
- label {
1960
- grid row: 0, column: 0, columnspan: 17
1961
- text 'Select a region of text and then apply formatting from the toolbar'
1962
- }
1963
-
1964
1973
  column_index = -1
1965
1974
 
1966
1975
  combobox {
@@ -1992,7 +2001,7 @@ class HelloText
1992
2001
  orient 'vertical'
1993
2002
  }
1994
2003
 
1995
- button {
2004
+ @bold_button = button {
1996
2005
  grid row: 1, column: column_index += 1, column_weight: 0
1997
2006
  text 'B'
1998
2007
  style font: {weight: 'bold'}
@@ -2002,7 +2011,7 @@ class HelloText
2002
2011
  end
2003
2012
  }
2004
2013
 
2005
- button {
2014
+ @italic_button = button {
2006
2015
  grid row: 1, column: column_index += 1, column_weight: 0
2007
2016
  text 'I'
2008
2017
  style font: {slant: 'italic'}
@@ -2012,7 +2021,7 @@ class HelloText
2012
2021
  end
2013
2022
  }
2014
2023
 
2015
- button {
2024
+ @underline_button = button {
2016
2025
  grid row: 1, column: column_index += 1, column_weight: 0
2017
2026
  text 'U'
2018
2027
  style font: {underline: true}
@@ -2021,36 +2030,36 @@ class HelloText
2021
2030
  @text.toggle_selection_font_format('underline', true)
2022
2031
  end
2023
2032
  }
2024
-
2033
+
2025
2034
  separator {
2026
2035
  grid row: 1, column: column_index += 1, column_weight: 0
2027
2036
  orient 'vertical'
2028
2037
  }
2029
2038
 
2030
- button {
2039
+ @justify_left_button = button {
2031
2040
  grid row: 1, column: column_index += 1, column_weight: 0
2032
- image File.expand_path("images/cut.png", __dir__), subsample: 32
2041
+ image File.expand_path("images/align-left.png", __dir__), subsample: 32
2033
2042
 
2034
2043
  on('command') do
2035
- @text.text_cut
2044
+ @text.add_selection_format('justify', 'left')
2036
2045
  end
2037
2046
  }
2038
2047
 
2039
- button {
2048
+ @justify_center_button = button {
2040
2049
  grid row: 1, column: column_index += 1, column_weight: 0
2041
- image File.expand_path("images/copy.png", __dir__), subsample: 32
2050
+ image File.expand_path("images/align-center.png", __dir__), subsample: 32
2042
2051
 
2043
2052
  on('command') do
2044
- @text.text_copy
2053
+ @text.add_selection_format('justify', 'center')
2045
2054
  end
2046
2055
  }
2047
2056
 
2048
- button {
2057
+ @justify_right_button = button {
2049
2058
  grid row: 1, column: column_index += 1, column_weight: 0
2050
- image File.expand_path("images/paste.png", __dir__), subsample: 32
2059
+ image File.expand_path("images/align-right.png", __dir__), subsample: 32
2051
2060
 
2052
2061
  on('command') do
2053
- @text.text_paste
2062
+ @text.add_selection_format('justify', 'right')
2054
2063
  end
2055
2064
  }
2056
2065
 
@@ -2061,51 +2070,51 @@ class HelloText
2061
2070
 
2062
2071
  button {
2063
2072
  grid row: 1, column: column_index += 1, column_weight: 0
2064
- image File.expand_path("images/align-left.png", __dir__), subsample: 32
2073
+ image File.expand_path("images/picture.png", __dir__), subsample: 32
2065
2074
 
2066
2075
  on('command') do
2067
- @text.add_selection_format('justify', 'left')
2076
+ @text.get_open_file_to_insert_image
2068
2077
  end
2069
2078
  }
2070
2079
 
2071
2080
  button {
2072
2081
  grid row: 1, column: column_index += 1, column_weight: 0
2073
- image File.expand_path("images/align-center.png", __dir__), subsample: 32
2082
+ image File.expand_path("images/search.png", __dir__), subsample: 32
2074
2083
 
2075
2084
  on('command') do
2076
- @text.add_selection_format('justify', 'center')
2085
+ show_find_dialog
2077
2086
  end
2078
2087
  }
2079
2088
 
2089
+ separator {
2090
+ grid row: 1, column: column_index += 1, column_weight: 0
2091
+ orient 'vertical'
2092
+ }
2093
+
2080
2094
  button {
2081
2095
  grid row: 1, column: column_index += 1, column_weight: 0
2082
- image File.expand_path("images/align-right.png", __dir__), subsample: 32
2096
+ image File.expand_path("images/cut.png", __dir__), subsample: 32
2083
2097
 
2084
2098
  on('command') do
2085
- @text.add_selection_format('justify', 'right')
2099
+ @text.text_cut
2086
2100
  end
2087
2101
  }
2088
2102
 
2089
- separator {
2090
- grid row: 1, column: column_index += 1, column_weight: 0
2091
- orient 'vertical'
2092
- }
2093
-
2094
2103
  button {
2095
2104
  grid row: 1, column: column_index += 1, column_weight: 0
2096
- image File.expand_path("images/undo.png", __dir__), subsample: 32
2105
+ image File.expand_path("images/copy.png", __dir__), subsample: 32
2097
2106
 
2098
2107
  on('command') do
2099
- @text.edit_undo
2108
+ @text.text_copy
2100
2109
  end
2101
2110
  }
2102
2111
 
2103
2112
  button {
2104
2113
  grid row: 1, column: column_index += 1, column_weight: 0
2105
- image File.expand_path("images/redo.png", __dir__), subsample: 32
2114
+ image File.expand_path("images/paste.png", __dir__), subsample: 32
2106
2115
 
2107
2116
  on('command') do
2108
- @text.edit_redo
2117
+ @text.text_paste
2109
2118
  end
2110
2119
  }
2111
2120
 
@@ -2114,12 +2123,22 @@ class HelloText
2114
2123
  orient 'vertical'
2115
2124
  }
2116
2125
 
2126
+
2117
2127
  button {
2118
2128
  grid row: 1, column: column_index += 1, column_weight: 0
2119
- image File.expand_path("images/picture.png", __dir__), subsample: 32
2129
+ image File.expand_path("images/undo.png", __dir__), subsample: 32
2120
2130
 
2121
2131
  on('command') do
2122
- @text.get_open_file_to_insert_image
2132
+ @text.edit_undo
2133
+ end
2134
+ }
2135
+
2136
+ button {
2137
+ grid row: 1, column: column_index += 1, column_weight: 0
2138
+ image File.expand_path("images/redo.png", __dir__), subsample: 32
2139
+
2140
+ on('command') do
2141
+ @text.edit_redo
2123
2142
  end
2124
2143
  }
2125
2144
  }
@@ -2129,8 +2148,67 @@ class HelloText
2129
2148
  wrap 'word'
2130
2149
  undo true
2131
2150
  value <=> [self, :document]
2151
+
2152
+ on('KeyPress') do |event|
2153
+ show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
2154
+ end
2155
+
2156
+ on('InsertMarkMoved') do
2157
+ self.font_family = @text.applied_font_format_value('family')
2158
+ self.font_size = @text.applied_font_format_value('size')
2159
+ @bold_button.default = @text.applied_font_format_value('weight') == 'bold' ? 'active' : 'normal'
2160
+ @italic_button.default = @text.applied_font_format_value('slant') == 'italic' ? 'active' : 'normal'
2161
+ @underline_button.default = @text.applied_font_format_value('underline') == true ? 'active' : 'normal'
2162
+ self.background = @text.applied_format_value('background')
2163
+ self.foreground = @text.applied_format_value('foreground')
2164
+ @justify_left_button.default = @text.applied_format_value('justify') == 'left' ? 'active' : 'normal'
2165
+ @justify_center_button.default = @text.applied_format_value('justify') == 'center' ? 'active' : 'normal'
2166
+ @justify_right_button.default = @text.applied_format_value('justify') == 'right' ? 'active' : 'normal'
2167
+ end
2132
2168
  }
2133
- }.open
2169
+ }
2170
+ @root.open
2171
+ end
2172
+
2173
+ def show_find_dialog
2174
+ toplevel(@root) { |tl|
2175
+ title 'Find'
2176
+
2177
+ label {
2178
+ text 'Text:'
2179
+ }
2180
+ entry { |e|
2181
+ focus true
2182
+ text <=> [
2183
+ self,
2184
+ :find_text,
2185
+ after_write: lambda do
2186
+ text_index = @text.search(/#{find_text}/i, 'insert')
2187
+ unless text_index.to_s.empty?
2188
+ @text.tag_remove('sel', '1.0', 'end')
2189
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
2190
+ end
2191
+ end
2192
+ ]
2193
+
2194
+ on('KeyPress') do |event|
2195
+ if event.keysym == 'Return'
2196
+ find
2197
+ elsif event.keysym == 'Escape'
2198
+ tl.grab_release
2199
+ tl.destroy
2200
+ end
2201
+ end
2202
+ }
2203
+ button {
2204
+ text 'Find'
2205
+ default 'active'
2206
+
2207
+ on('command') do
2208
+ find
2209
+ end
2210
+ }
2211
+ }
2134
2212
  end
2135
2213
  end
2136
2214
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.33
1
+ 0.0.34
Binary file
@@ -36,9 +36,11 @@ module Glimmer
36
36
  case listener_name.to_s.downcase
37
37
  when '<<modified>>', '<modified>', 'modified'
38
38
  modified_listener = Proc.new do |*args|
39
+ @modified_count ||= 0
40
+ @modified_count += 1
39
41
  listener.call(*args)
40
42
  apply_all_tag
41
- @insert_mark_moved_proc.call
43
+ @insert_mark_moved_proc&.call
42
44
  @tk.modified = false
43
45
  end
44
46
  @tk.bind('<Modified>', modified_listener)
@@ -49,16 +51,16 @@ module Glimmer
49
51
  when 'insertmarkmove', 'insertmarkmoved', 'insert_mark_move', 'insert_mark_moved'
50
52
  if @insert_mark_moved_proc.nil?
51
53
  handle_listener('KeyPress') do |event|
52
- @insert_mark_moved_proc.call
54
+ @insert_mark_moved_proc&.call
53
55
  end
54
56
  handle_listener('KeyRelease') do |event|
55
- @insert_mark_moved_proc.call
57
+ @insert_mark_moved_proc&.call
56
58
  end
57
59
  handle_listener('ButtonPress') do |event|
58
- @insert_mark_moved_proc.call
60
+ @insert_mark_moved_proc&.call
59
61
  end
60
62
  handle_listener('ButtonRelease') do |event|
61
- @insert_mark_moved_proc.call
63
+ @insert_mark_moved_proc&.call
62
64
  end
63
65
  end
64
66
  @insert_mark = @tk.index('insert')
@@ -72,44 +74,71 @@ module Glimmer
72
74
  else
73
75
  apply_all_tag
74
76
  # TODO make listener pass an event that has a modifiers attribute for easy representation of :shift, :meta, :control, etc... while a letter button is pressed
77
+ @listeners ||= {}
75
78
  begin
76
- @tk.tag_bind(ALL_TAG, listener_name, &listener)
79
+ @listeners[listener_name] ||= []
80
+ @tk.tag_bind(ALL_TAG, listener_name) { |event| @listeners[listener_name].each {|l| l.call(event)} } if @listeners[listener_name].empty?
81
+ @listeners[listener_name] << listener
77
82
  rescue => e
83
+ @listeners.delete(listener_name)
78
84
  Glimmer::Config.logger.debug {"Unable to bind to #{listener_name} .. attempting to surround with <>"}
79
85
  Glimmer::Config.logger.debug {e.full_message}
80
86
  listener_name = "<#{listener_name}" if !listener_name.start_with?('<')
81
87
  listener_name = "#{listener_name}>" if !listener_name.end_with?('>')
82
- @tk.tag_bind(ALL_TAG, listener_name, &listener)
88
+ @listeners[listener_name] ||= []
89
+ @tk.tag_bind(ALL_TAG, listener_name) { |event| @listeners[listener_name].each {|l| l.call(event)} } if @listeners[listener_name].empty?
90
+ @listeners[listener_name] << listener
83
91
  end
84
92
  end
85
93
  end
86
94
 
87
- def add_selection_format(option, value)
88
- process_selection_ranges { |range_start, range_end| add_format(range_start, range_end, option, value) }
95
+ def edit_undo
96
+ @tk.edit_undo if @modified_count.to_i > 2 # <Modified> fires twice the first time, which is equivalent to one change.
89
97
  end
90
98
 
91
- def remove_selection_format(option, value)
92
- process_selection_ranges { |range_start, range_end| remove_format(range_start, range_end, option, value) }
99
+ def edit_redo
100
+ begin
101
+ @tk.edit_redo
102
+ rescue => e
103
+ # No Op
104
+ end
105
+ end
106
+
107
+ def add_selection_format(option, value, no_selection_default: :insert_word)
108
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| add_format(range_start, range_end, option, value) }
93
109
  end
94
110
 
95
- def toggle_selection_format(option, value)
96
- process_selection_ranges { |range_start, range_end| toggle_format(range_start, range_end, option, value) }
111
+ def remove_selection_format(option, value, no_selection_default: :insert_word)
112
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| remove_format(range_start, range_end, option, value) }
97
113
  end
98
114
 
99
- def add_selection_font_format(option, value)
100
- process_selection_ranges { |range_start, range_end| add_font_format(range_start, range_end, option, value) }
115
+ def toggle_selection_format(option, value, no_selection_default: :insert_word)
116
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| toggle_format(range_start, range_end, option, value) }
101
117
  end
102
118
 
103
- def remove_selection_font_format(option, value)
104
- process_selection_ranges { |range_start, range_end| remove_font_format(range_start, range_end, option, value) }
119
+ def add_selection_font_format(option, value, no_selection_default: :insert_word)
120
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| add_font_format(range_start, range_end, option, value) }
105
121
  end
106
122
 
107
- def toggle_selection_font_format(option, value)
108
- process_selection_ranges { |range_start, range_end| toggle_font_format(range_start, range_end, option, value) }
123
+ def remove_selection_font_format(option, value, no_selection_default: :insert_word)
124
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| remove_font_format(range_start, range_end, option, value) }
109
125
  end
110
126
 
111
- def process_selection_ranges(&processor)
112
- @tk.tag_ranges('sel').each do |region|
127
+ def toggle_selection_font_format(option, value, no_selection_default: :insert_word)
128
+ process_selection_ranges(no_selection_default: no_selection_default) { |range_start, range_end| toggle_font_format(range_start, range_end, option, value) }
129
+ end
130
+
131
+ def process_selection_ranges(no_selection_default: :insert_word, &processor)
132
+ regions = @tk.tag_ranges('sel')
133
+ if regions.empty?
134
+ case no_selection_default
135
+ when :insert_word
136
+ regions = [[@tk.index('insert wordstart'), @tk.index('insert wordend + 1 char')]]
137
+ when :insert_letter
138
+ regions = [[@tk.index('insert'), @tk.index('insert + 1 char')]]
139
+ end
140
+ end
141
+ regions.each do |region|
113
142
  range_start = region.first
114
143
  range_end = region.last
115
144
  processor.call(range_start, range_end)
@@ -151,7 +180,7 @@ module Glimmer
151
180
 
152
181
  def add_format(region_start, region_end, option, value)
153
182
  @@tag_number = 0 unless defined?(@@tag_number)
154
- tag = "tag#{@@tag_number += 1}"
183
+ tag = "tag_#{option}_#{@@tag_number += 1}"
155
184
  @tk.tag_configure(tag, {option => value})
156
185
  @tk.tag_add(tag, region_start, region_end)
157
186
  tag
@@ -202,7 +231,7 @@ module Glimmer
202
231
  def applied_font_format_tags_and_regions(region_start, region_end)
203
232
  lines = value.split("\n")
204
233
  tags_and_regions = []
205
- all_tag_names = @tk.tag_names - ['sel', ALL_TAG]
234
+ all_tag_names = (@tk.tag_names - ['sel', ALL_TAG]).select {|tag_name| tag_name.include?('_font_')}
206
235
  (region_start.to_i..region_end.to_i).each do |line_number|
207
236
  start_character_index = 0
208
237
  start_character_index = region_start.to_s.split('.').last.to_i if line_number == region_start.to_i
@@ -107,11 +107,6 @@ class HelloText
107
107
  frame {
108
108
  grid row: 0, column: 0
109
109
 
110
- label {
111
- grid row: 0, column: 0, columnspan: 17
112
- text 'Select a region of text and then apply formatting from the toolbar'
113
- }
114
-
115
110
  column_index = -1
116
111
 
117
112
  combobox {
@@ -172,36 +167,36 @@ class HelloText
172
167
  @text.toggle_selection_font_format('underline', true)
173
168
  end
174
169
  }
175
-
170
+
176
171
  separator {
177
172
  grid row: 1, column: column_index += 1, column_weight: 0
178
173
  orient 'vertical'
179
174
  }
180
175
 
181
- button {
176
+ @justify_left_button = button {
182
177
  grid row: 1, column: column_index += 1, column_weight: 0
183
- image File.expand_path("images/cut.png", __dir__), subsample: 32
178
+ image File.expand_path("images/align-left.png", __dir__), subsample: 32
184
179
 
185
180
  on('command') do
186
- @text.text_cut
181
+ @text.add_selection_format('justify', 'left')
187
182
  end
188
183
  }
189
184
 
190
- button {
185
+ @justify_center_button = button {
191
186
  grid row: 1, column: column_index += 1, column_weight: 0
192
- image File.expand_path("images/copy.png", __dir__), subsample: 32
187
+ image File.expand_path("images/align-center.png", __dir__), subsample: 32
193
188
 
194
189
  on('command') do
195
- @text.text_copy
190
+ @text.add_selection_format('justify', 'center')
196
191
  end
197
192
  }
198
193
 
199
- button {
194
+ @justify_right_button = button {
200
195
  grid row: 1, column: column_index += 1, column_weight: 0
201
- image File.expand_path("images/paste.png", __dir__), subsample: 32
196
+ image File.expand_path("images/align-right.png", __dir__), subsample: 32
202
197
 
203
198
  on('command') do
204
- @text.text_paste
199
+ @text.add_selection_format('justify', 'right')
205
200
  end
206
201
  }
207
202
 
@@ -210,53 +205,53 @@ class HelloText
210
205
  orient 'vertical'
211
206
  }
212
207
 
213
- @justify_left_button = button {
208
+ button {
214
209
  grid row: 1, column: column_index += 1, column_weight: 0
215
- image File.expand_path("images/align-left.png", __dir__), subsample: 32
210
+ image File.expand_path("images/picture.png", __dir__), subsample: 32
216
211
 
217
212
  on('command') do
218
- @text.add_selection_format('justify', 'left')
213
+ @text.get_open_file_to_insert_image
219
214
  end
220
215
  }
221
216
 
222
- @justify_center_button = button {
217
+ button {
223
218
  grid row: 1, column: column_index += 1, column_weight: 0
224
- image File.expand_path("images/align-center.png", __dir__), subsample: 32
219
+ image File.expand_path("images/search.png", __dir__), subsample: 32
225
220
 
226
221
  on('command') do
227
- @text.add_selection_format('justify', 'center')
222
+ show_find_dialog
228
223
  end
229
224
  }
230
225
 
231
- @justify_right_button = button {
226
+ separator {
232
227
  grid row: 1, column: column_index += 1, column_weight: 0
233
- image File.expand_path("images/align-right.png", __dir__), subsample: 32
234
-
235
- on('command') do
236
- @text.add_selection_format('justify', 'right')
237
- end
228
+ orient 'vertical'
238
229
  }
239
230
 
240
- separator {
231
+ button {
241
232
  grid row: 1, column: column_index += 1, column_weight: 0
242
- orient 'vertical'
233
+ image File.expand_path("images/cut.png", __dir__), subsample: 32
234
+
235
+ on('command') do
236
+ @text.text_cut
237
+ end
243
238
  }
244
239
 
245
240
  button {
246
241
  grid row: 1, column: column_index += 1, column_weight: 0
247
- image File.expand_path("images/undo.png", __dir__), subsample: 32
242
+ image File.expand_path("images/copy.png", __dir__), subsample: 32
248
243
 
249
244
  on('command') do
250
- @text.edit_undo
245
+ @text.text_copy
251
246
  end
252
247
  }
253
248
 
254
249
  button {
255
250
  grid row: 1, column: column_index += 1, column_weight: 0
256
- image File.expand_path("images/redo.png", __dir__), subsample: 32
251
+ image File.expand_path("images/paste.png", __dir__), subsample: 32
257
252
 
258
253
  on('command') do
259
- @text.edit_redo
254
+ @text.text_paste
260
255
  end
261
256
  }
262
257
 
@@ -265,21 +260,22 @@ class HelloText
265
260
  orient 'vertical'
266
261
  }
267
262
 
263
+
268
264
  button {
269
265
  grid row: 1, column: column_index += 1, column_weight: 0
270
- image File.expand_path("images/picture.png", __dir__), subsample: 32
266
+ image File.expand_path("images/undo.png", __dir__), subsample: 32
271
267
 
272
268
  on('command') do
273
- @text.get_open_file_to_insert_image
269
+ @text.edit_undo
274
270
  end
275
271
  }
276
272
 
277
273
  button {
278
274
  grid row: 1, column: column_index += 1, column_weight: 0
279
- image File.expand_path("images/search.png", __dir__), subsample: 32
275
+ image File.expand_path("images/redo.png", __dir__), subsample: 32
280
276
 
281
277
  on('command') do
282
- show_find_dialog
278
+ @text.edit_redo
283
279
  end
284
280
  }
285
281
  }
@@ -293,7 +289,7 @@ class HelloText
293
289
  on('KeyPress') do |event|
294
290
  show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
295
291
  end
296
-
292
+
297
293
  on('InsertMarkMoved') do
298
294
  self.font_family = @text.applied_font_format_value('family')
299
295
  self.font_size = @text.applied_font_format_value('size')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-tk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-30 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer