glimmer-dsl-tk 0.0.33 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33884eabc43f9c6b019d12a45f75e19212e2969d447f743e29e9db5cf81c615b
4
- data.tar.gz: 0f0e3558279a70b03aaaf3e7733125eee5bfb5cce320ea34a6bc838803227755
3
+ metadata.gz: 2454b5a3d7bd7159328cab0c0c82a4ebcdb54066bec28a1549e3cbca61d1bd8d
4
+ data.tar.gz: 7535984b2838617c7a40ee336c653e6c5c9029c7e49b3a4a13f1815897ecec8d
5
5
  SHA512:
6
- metadata.gz: f9dac142530aa07249e92dc4cc314a028f7652582562031b415eaab33ac5c0a1207ef2d4f7bbe330bf62715d78f71727a3ef9f26eb761e52efdcc03778a39ac7
7
- data.tar.gz: 117a6cd4b7fd8472c87b8e4817097d3b6f1c0ff1f765c8fa851b239fff453bbcc2bc7dc69a800d1c9fbee6669b87f821f2d2fa8cef4a407b59c1607c582a0aaf
6
+ metadata.gz: d377872669979a76bf149aec8683ade86fadd7efa50817abe4f8e582a0f3b53ac354759f3e7e6aa4e683fcd6296308eb7339c049718fcd7c673e4452f1052614
7
+ data.tar.gz: b321a3e34b16f9a1719797c51f25521a48c4c12ba39f92a730618dedc54f564754f24e73f60118023213583e3629c188643684cc7d326628613c982c0a87e7d0
data/CHANGELOG.md CHANGED
@@ -1,8 +1,36 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.37
4
+
5
+ - Have `text` widget grab focus after every formatting modification in Hello, Text! (e.g. after clicking `B` for Bold)
6
+
7
+ ## 0.0.36
8
+
9
+ - Hello, Toplevel! (Custom Window and Custom Dialog)
10
+ - Support `mac_style` attribute under `toplevel`
11
+ - Support registering multiple general event listeners on widgets (previously, later event listener registrations replaced former ones)
12
+ - Support `escapable true` property under `root` and `toplevel` to close on hitting ESCAPE button
13
+
14
+ ## 0.0.35
15
+
16
+ - Improved Meta-Sample by utilizing Ruby from `RbConfig.ruby`
17
+ - Improved girb_runner.rb to be more platform independent
18
+ - Fixed `text` widget binding of standard bind events (e.g. `'KeyPress'` or `'ButtonPress'`)
19
+ - Fixed Hello, Text! issue with not being able to bring up Find Dialog once all text is deleted and new text is entered
20
+ - Fixed undo/redo issue
21
+
22
+ ## 0.0.34
23
+
24
+ - When applying a `text` selection format without having a selection, have it apply to current insert mark word
25
+ - Support registering multiple general event listeners on `text` widget (previously, later event listener registrations replaced former ones)
26
+ - 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`)
27
+ - Make sure to only allow `text` undo/redo when there are changes to be undoed/redoed
28
+ - Fix issue with Hello, Text! Find Dialog not coming up with keyboard shortcut (e.g. CMD+F) anymore
29
+ - 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)
30
+
3
31
  ## 0.0.33
4
32
 
5
- - Support `text` widget `InsertMarkMoved` listener event to track insert mark movement (or alises `InsertMarkMove`, `insert_mark_move`, `insert_mark_moved`, all case-insensitive)
33
+ - Support `text` widget `InsertMarkMoved` listener event to track insert mark movement (or aliases `InsertMarkMove`, `insert_mark_move`, `insert_mark_moved`, all case-insensitive)
6
34
  - Support `entry` widget `changed` and `modified` listener event aliases for `change` event
7
35
  - 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
36
  - 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.37
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)
@@ -55,8 +55,9 @@ NOTE: Glimmer DSL for Tk is currently in early alpha mode (incomplete). Please h
55
55
 
56
56
  Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
57
57
  - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
58
- - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
59
58
  - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
59
+ - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library)
60
+ - [glimmer-dsl-gtk](https://github.com/AndyObtiva/glimmer-dsl-gtk): Ruby-GNOME Desktop Development GUI Library
60
61
  - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
61
62
  - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
62
63
 
@@ -83,6 +84,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
83
84
  - [Notebook Frame](#notebook-frame)
84
85
  - [Icon Photo](#icon-photo)
85
86
  - [Root Background](#root-background)
87
+ - [Toplevel Mac Style](#toplevel-mac-style)
86
88
  - [Text Defaults](#text-defaults)
87
89
  - [The Grid Geometry Manager](#the-grid-geometry-manager)
88
90
  - [Data-Binding](#data-binding)
@@ -104,6 +106,7 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
104
106
  - [Hello, Radiobutton!](#hello-radiobutton)
105
107
  - [Hello, Frame!](#hello-frame)
106
108
  - [Hello, Root!](#hello-root)
109
+ - [Hello, Toplevel!](#hello-toplevel)
107
110
  - [Hello, Notebook!](#hello-notebook)
108
111
  - [Hello, Label!](#hello-label)
109
112
  - [Hello, Message Box!](#hello-message-box)
@@ -158,7 +161,7 @@ gem install glimmer-dsl-tk
158
161
 
159
162
  Add the following to `Gemfile`:
160
163
  ```
161
- gem 'glimmer-dsl-tk', '~> 0.0.33'
164
+ gem 'glimmer-dsl-tk', '~> 0.0.37'
162
165
  ```
163
166
 
164
167
  And, then run:
@@ -349,15 +352,23 @@ The `text` widget is enhanced by [Glimmer DSL for Tk](https://rubygems.org/gems/
349
352
  - `add_font_format(region_start, region_end, font_option, value)`
350
353
  - `remove_font_format(region_start, region_end, font_option, value)`
351
354
  - `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)`
355
+ - `add_selection_format(option, value, no_selection_default: :insert_word, focus: true)`: adds format to selection. If there is no selection, then applies format to current insert mark word.
356
+ - `remove_selection_format(option, value, no_selection_default: :insert_word, focus: true)`
357
+ - `toggle_selection_format(option, value, no_selection_default: :insert_word, focus: true)`: toggles format on selection. If there is no selection, then toggles format on current insert mark word.
358
+ - `add_selection_font_format(font_option, value, no_selection_default: :insert_word, focus: true)`
359
+ - `remove_selection_font_format(font_option, value, no_selection_default: :insert_word, focus: true)`
360
+ - `toggle_selection_font_format(font_option, value, no_selection_default: :insert_word, focus: true)`
358
361
  - `text#insert_image(text_index, *image_args)`: inserts image into `text` `value` content at `text_index` location (e.g. `'insert'`)
359
362
  - `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
363
 
364
+ The `:no_selection_default` keyword arg to `*_selection_*` methods determines what region to cover when no explicit selection is set:
365
+ - `:insert_word`: current word for insert mark
366
+ - `:insert_letter`: current letter for insert mark
367
+ - `:none`: no behavior when no selection is in place
368
+
369
+ The `:focus` keyword arg defaults to `true` to indicate that the `text` widget should automatically grab focus after formatting modification.
370
+ Also, the `:focus` keyword arg can have an integer value representing number of milliseconds after which to grab focus once the formatting modification is done. This helps in special situations like when making the formatting modification from a combobox, which takes a while before relinquishing focus, so adding `100` millisecond delay helps ensure the `text` widget grabs focus after modification. Check [Hello, Text!](#hello-text) for an example of that.
371
+
361
372
  Available options:
362
373
 
363
374
  - `background`
@@ -473,6 +484,20 @@ root {
473
484
 
474
485
  `root` `background` color attribute is automatically set to `'#ececec'` on the Mac to avoid having a non-native-looking light-colored background.
475
486
 
487
+ #### Toplevel Mac Style
488
+
489
+ Mac has special support for mac styles in Tk `toplevel` via the `mac_style` attribute, which can receive 1 to 2 arguments. `mac_style`'s first argument (`mac_class`) and second argument (`mac_attribute_list`) can be chosen from this page:
490
+
491
+ https://wiki.tcl-lang.org/page/MacWindowStyle
492
+
493
+ Behind the scenes, `mac_style` automatically calls out to:
494
+
495
+ ```ruby
496
+ Tk.tk_call("::tk::unsupported::MacWindowStyle", "style", tk_toplevel_widget, mac_class, mac_attribute_list)
497
+ ```
498
+
499
+ More details can be found at the [Hello, Toplevel!](#hello-toplevel) sample.
500
+
476
501
  #### Text Defaults
477
502
 
478
503
  `text` widget has these defaults:
@@ -1327,7 +1352,7 @@ Glimmer app:
1327
1352
 
1328
1353
  ### Hello, Root!
1329
1354
 
1330
- Glimmer code (from [samples/hello/hello_frame.rb](samples/hello/hello_frame.rb)):
1355
+ Glimmer code (from [samples/hello/hello_root.rb](samples/hello/hello_root.rb)):
1331
1356
 
1332
1357
  ```ruby
1333
1358
  require 'glimmer-dsl-tk'
@@ -1379,6 +1404,208 @@ Glimmer app:
1379
1404
 
1380
1405
  ![glimmer dsl tk screenshot sample hello root bye](images/glimmer-dsl-tk-screenshot-sample-hello-root-bye.png)
1381
1406
 
1407
+ ### Hello, Toplevel!
1408
+
1409
+ `toplevel` widgets represent windows nested under `root`, which can be modeless (custom windows) or modal (dialogs that take the focus away from the owning window behind them until closed).
1410
+
1411
+ Mac has special support for mac styles in Tk `toplevel` via the `mac_style` attribute, which can receive 1 to 2 arguments. `mac_style`'s first argument (`mac_class`) and second argument (`mac_attribute_list`) can be chosen from this page:
1412
+
1413
+ https://wiki.tcl-lang.org/page/MacWindowStyle
1414
+
1415
+ Glimmer code (from [samples/hello/hello_toplevel.rb](samples/hello/hello_toplevel.rb)):
1416
+
1417
+ ```ruby
1418
+ require 'glimmer-dsl-tk'
1419
+
1420
+ include Glimmer
1421
+
1422
+ def toplevel_content
1423
+ frame {
1424
+ label {
1425
+ text "This is a fully custom toplevel, meaning you can add any widgets here!\nYou can press the ESCAPE button on the keyboard to close."
1426
+ }
1427
+ separator
1428
+ checkbutton {
1429
+ text 'This is a checkbutton'
1430
+ }
1431
+ radiobutton {
1432
+ text 'This is a radiobutton'
1433
+ }
1434
+ }
1435
+ end
1436
+
1437
+ root { |root_window|
1438
+ title 'Hello, Toplevel!'
1439
+
1440
+ button {
1441
+ text 'Nested Window'
1442
+
1443
+ on('command') do
1444
+ toplevel(root_window) {
1445
+ title 'Custom Window'
1446
+ escapable true
1447
+ x 150
1448
+ y 180
1449
+ width 500
1450
+ height 200
1451
+ minsize 500, 100
1452
+ maxsize 1000, 300
1453
+
1454
+ toplevel_content
1455
+ }
1456
+ end
1457
+ }
1458
+
1459
+ button {
1460
+ text 'Transparent Window'
1461
+
1462
+ on('command') do
1463
+ toplevel(root_window) {
1464
+ title 'Transparent Window'
1465
+ escapable true
1466
+ alpha 0.85
1467
+ width 250
1468
+ height 100
1469
+ resizable false, false # not resizable horizontally or vertically
1470
+
1471
+ frame {
1472
+ label {
1473
+ text "This is a transparent window\nYou can hit ESCAPE to close."
1474
+ anchor 'center'
1475
+ }
1476
+ }
1477
+ }
1478
+ end
1479
+ }
1480
+
1481
+ button {
1482
+ text 'Fullscreen Window'
1483
+
1484
+ on('command') do
1485
+ toplevel(root_window) {
1486
+ title 'Fullscreen Window'
1487
+ escapable true
1488
+ fullscreen true
1489
+
1490
+ frame {
1491
+ label {
1492
+ text "This is a fullscreen window\nYou can hit ESCAPE to close."
1493
+ anchor 'center'
1494
+ }
1495
+ }
1496
+ }
1497
+ end
1498
+ }
1499
+
1500
+ if OS.mac?
1501
+ # Mac has special support for mac styles in Tk `toplevel`
1502
+ # `mac_style` first argument (`mac_class`) and second argument (`mac_attribute_list`) can be chosen from this page: https://wiki.tcl-lang.org/page/MacWindowStyle
1503
+
1504
+ button {
1505
+ text 'Mac Plain (No-Button-Modeless) Window'
1506
+
1507
+ on('command') do
1508
+ toplevel(root_window) { |t|
1509
+ title 'Mac Plain (No-Button-Modeless) Window'
1510
+ escapable true
1511
+ mac_style 'plain'
1512
+
1513
+ toplevel_content
1514
+ }
1515
+ end
1516
+ }
1517
+
1518
+ button {
1519
+ text 'Mac Floating (Close-Button-Modeless) Window'
1520
+
1521
+ on('command') do
1522
+ toplevel(root_window) { |t|
1523
+ title 'Mac Floating (Close-Button-Modeless) Window'
1524
+ escapable true
1525
+ mac_style 'floating'
1526
+
1527
+ toplevel_content
1528
+ }
1529
+ end
1530
+ }
1531
+
1532
+ button {
1533
+ text 'Mac Document (All-Button-Modeless) Window'
1534
+
1535
+ on('command') do
1536
+ toplevel(root_window) { |t|
1537
+ title 'Mac Document (All-Button-Modeless) Window'
1538
+ escapable true
1539
+ mac_style 'document'
1540
+
1541
+ toplevel_content
1542
+ }
1543
+ end
1544
+ }
1545
+
1546
+ button {
1547
+ text 'Mac Utility (Close-Button-Modal) Dialog'
1548
+
1549
+ on('command') do
1550
+ toplevel(root_window) { |t|
1551
+ title 'Mac Utility (Close-Button-Modal) Dialog'
1552
+ escapable true
1553
+ mac_style 'utility'
1554
+
1555
+ toplevel_content
1556
+ }
1557
+ end
1558
+ }
1559
+
1560
+ button {
1561
+ text 'Mac Utility with Attribute List (All-Button-Modal) Dialog'
1562
+
1563
+ on('command') do
1564
+ toplevel(root_window) { |t|
1565
+ title 'Mac Utility with Attribute List (All-Button-Modal) Dialog'
1566
+ escapable true
1567
+ mac_style 'utility', 'closeBox collapseBox resizable horizontalZoom verticalZoom sideTitlebar'
1568
+
1569
+ toplevel_content
1570
+ }
1571
+ end
1572
+ }
1573
+ end
1574
+ }.open
1575
+ ```
1576
+
1577
+ Run with [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1578
+
1579
+ ```
1580
+ ruby -r glimmer-dsl-tk -e "require 'samples/hello/hello_toplevel'"
1581
+ ```
1582
+
1583
+ Alternatively, run from cloned project without [glimmer-dsl-tk](https://rubygems.org/gems/glimmer-dsl-tk) gem installed:
1584
+
1585
+ ```
1586
+ ruby -r ./lib/glimmer-dsl-tk.rb samples/hello/hello_toplevel.rb
1587
+ ```
1588
+
1589
+ Glimmer app:
1590
+
1591
+ ![glimmer dsl tk screenshot sample hello toplevel 1](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel.png)
1592
+
1593
+ ![glimmer dsl tk screenshot sample hello toplevel 2](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-custom-window.png)
1594
+
1595
+ ![glimmer dsl tk screenshot sample hello toplevel 3](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-transparent-window.png)
1596
+
1597
+ ![glimmer dsl tk screenshot sample hello toplevel 4](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-fullscreen-window.png)
1598
+
1599
+ ![glimmer dsl tk screenshot sample hello toplevel 5](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-mac-plain-window.png)
1600
+
1601
+ ![glimmer dsl tk screenshot sample hello toplevel 6](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-mac-floating-window.png)
1602
+
1603
+ ![glimmer dsl tk screenshot sample hello toplevel 7](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-mac-document-window.png)
1604
+
1605
+ ![glimmer dsl tk screenshot sample hello toplevel 8](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-mac-utility-window.png)
1606
+
1607
+ ![glimmer dsl tk screenshot sample hello toplevel 9](images/glimmer-dsl-tk-screenshot-sample-hello-toplevel-mac-utility-with-attribute-list-window.png)
1608
+
1382
1609
  ### Hello, Notebook!
1383
1610
 
1384
1611
  Glimmer code (from [samples/hello/hello_notebook.rb](samples/hello/hello_notebook.rb)):
@@ -1869,7 +2096,7 @@ Glimmer app:
1869
2096
 
1870
2097
  ### Hello, Text!
1871
2098
 
1872
- You may use the META+F shortcut to bring up the Find Dialog.
2099
+ 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
2100
 
1874
2101
  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
2102
 
@@ -1921,7 +2148,7 @@ class HelloText
1921
2148
  MULTI_LINE_STRING
1922
2149
  end
1923
2150
 
1924
- attr_accessor :document
2151
+ attr_accessor :document, :find_text
1925
2152
 
1926
2153
  attr_accessor :foreground
1927
2154
 
@@ -1947,8 +2174,16 @@ class HelloText
1947
2174
  [FONT_SIZE_PROMPT] + (9..64).to_a.map(&:to_s)
1948
2175
  end
1949
2176
 
2177
+ def find
2178
+ text_index = @text.search(/#{find_text}/i, @text.tag_ranges('sel')&.first&.last || @text.index('insert'))
2179
+ unless text_index.to_s.empty?
2180
+ @text.tag_remove('sel', '1.0', 'end')
2181
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
2182
+ end
2183
+ end
2184
+
1950
2185
  def launch
1951
- root {
2186
+ @root = root {
1952
2187
  title 'Hello, Text!'
1953
2188
  width 1280
1954
2189
  height 800
@@ -1956,35 +2191,30 @@ class HelloText
1956
2191
  frame {
1957
2192
  grid row: 0, column: 0
1958
2193
 
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
2194
  column_index = -1
1965
2195
 
1966
- combobox {
2196
+ combobox { |cb|
1967
2197
  grid row: 1, column: column_index += 1, column_weight: 1
1968
2198
  readonly true
1969
- text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value) }]
2199
+ text <=> [self, :font_family, after_write: ->(value) { @text.toggle_selection_font_format('family', value == FONT_FAMILY_PROMPT ? 'Courier New' : value, focus: 100) }]
1970
2200
  }
1971
2201
 
1972
2202
  combobox {
1973
2203
  grid row: 1, column: column_index += 1, column_weight: 1
1974
2204
  readonly true
1975
- text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value) }]
2205
+ text <=> [self, :font_size, after_write: ->(value) { @text.toggle_selection_font_format('size', value == FONT_SIZE_PROMPT ? 13 : value, focus: 100) }]
1976
2206
  }
1977
2207
 
1978
2208
  combobox {
1979
2209
  grid row: 1, column: column_index += 1, column_weight: 1
1980
2210
  readonly true
1981
- text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value) }]
2211
+ text <=> [self, :foreground, after_write: ->(value) { @text.add_selection_format('foreground', value == FOREGROUND_PROMPT ? 'black' : value, focus: 100) }]
1982
2212
  }
1983
2213
 
1984
2214
  combobox {
1985
2215
  grid row: 1, column: column_index += 1, column_weight: 1
1986
2216
  readonly true
1987
- text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value) }]
2217
+ text <=> [self, :background, after_write: ->(value) { @text.add_selection_format('background', value == BACKGROUND_PROMPT ? 'white' : value, focus: 100) }]
1988
2218
  }
1989
2219
 
1990
2220
  separator {
@@ -1992,7 +2222,7 @@ class HelloText
1992
2222
  orient 'vertical'
1993
2223
  }
1994
2224
 
1995
- button {
2225
+ @bold_button = button {
1996
2226
  grid row: 1, column: column_index += 1, column_weight: 0
1997
2227
  text 'B'
1998
2228
  style font: {weight: 'bold'}
@@ -2002,7 +2232,7 @@ class HelloText
2002
2232
  end
2003
2233
  }
2004
2234
 
2005
- button {
2235
+ @italic_button = button {
2006
2236
  grid row: 1, column: column_index += 1, column_weight: 0
2007
2237
  text 'I'
2008
2238
  style font: {slant: 'italic'}
@@ -2012,7 +2242,7 @@ class HelloText
2012
2242
  end
2013
2243
  }
2014
2244
 
2015
- button {
2245
+ @underline_button = button {
2016
2246
  grid row: 1, column: column_index += 1, column_weight: 0
2017
2247
  text 'U'
2018
2248
  style font: {underline: true}
@@ -2021,36 +2251,36 @@ class HelloText
2021
2251
  @text.toggle_selection_font_format('underline', true)
2022
2252
  end
2023
2253
  }
2024
-
2254
+
2025
2255
  separator {
2026
2256
  grid row: 1, column: column_index += 1, column_weight: 0
2027
2257
  orient 'vertical'
2028
2258
  }
2029
2259
 
2030
- button {
2260
+ @justify_left_button = button {
2031
2261
  grid row: 1, column: column_index += 1, column_weight: 0
2032
- image File.expand_path("images/cut.png", __dir__), subsample: 32
2262
+ image File.expand_path("images/align-left.png", __dir__), subsample: 32
2033
2263
 
2034
2264
  on('command') do
2035
- @text.text_cut
2265
+ @text.add_selection_format('justify', 'left')
2036
2266
  end
2037
2267
  }
2038
2268
 
2039
- button {
2269
+ @justify_center_button = button {
2040
2270
  grid row: 1, column: column_index += 1, column_weight: 0
2041
- image File.expand_path("images/copy.png", __dir__), subsample: 32
2271
+ image File.expand_path("images/align-center.png", __dir__), subsample: 32
2042
2272
 
2043
2273
  on('command') do
2044
- @text.text_copy
2274
+ @text.add_selection_format('justify', 'center')
2045
2275
  end
2046
2276
  }
2047
2277
 
2048
- button {
2278
+ @justify_right_button = button {
2049
2279
  grid row: 1, column: column_index += 1, column_weight: 0
2050
- image File.expand_path("images/paste.png", __dir__), subsample: 32
2280
+ image File.expand_path("images/align-right.png", __dir__), subsample: 32
2051
2281
 
2052
2282
  on('command') do
2053
- @text.text_paste
2283
+ @text.add_selection_format('justify', 'right')
2054
2284
  end
2055
2285
  }
2056
2286
 
@@ -2061,51 +2291,51 @@ class HelloText
2061
2291
 
2062
2292
  button {
2063
2293
  grid row: 1, column: column_index += 1, column_weight: 0
2064
- image File.expand_path("images/align-left.png", __dir__), subsample: 32
2294
+ image File.expand_path("images/picture.png", __dir__), subsample: 32
2065
2295
 
2066
2296
  on('command') do
2067
- @text.add_selection_format('justify', 'left')
2297
+ @text.get_open_file_to_insert_image
2068
2298
  end
2069
2299
  }
2070
2300
 
2071
2301
  button {
2072
2302
  grid row: 1, column: column_index += 1, column_weight: 0
2073
- image File.expand_path("images/align-center.png", __dir__), subsample: 32
2303
+ image File.expand_path("images/search.png", __dir__), subsample: 32
2074
2304
 
2075
2305
  on('command') do
2076
- @text.add_selection_format('justify', 'center')
2306
+ show_find_dialog
2077
2307
  end
2078
2308
  }
2079
2309
 
2310
+ separator {
2311
+ grid row: 1, column: column_index += 1, column_weight: 0
2312
+ orient 'vertical'
2313
+ }
2314
+
2080
2315
  button {
2081
2316
  grid row: 1, column: column_index += 1, column_weight: 0
2082
- image File.expand_path("images/align-right.png", __dir__), subsample: 32
2317
+ image File.expand_path("images/cut.png", __dir__), subsample: 32
2083
2318
 
2084
2319
  on('command') do
2085
- @text.add_selection_format('justify', 'right')
2320
+ @text.text_cut
2086
2321
  end
2087
2322
  }
2088
2323
 
2089
- separator {
2090
- grid row: 1, column: column_index += 1, column_weight: 0
2091
- orient 'vertical'
2092
- }
2093
-
2094
2324
  button {
2095
2325
  grid row: 1, column: column_index += 1, column_weight: 0
2096
- image File.expand_path("images/undo.png", __dir__), subsample: 32
2326
+ image File.expand_path("images/copy.png", __dir__), subsample: 32
2097
2327
 
2098
2328
  on('command') do
2099
- @text.edit_undo
2329
+ @text.text_copy
2100
2330
  end
2101
2331
  }
2102
2332
 
2103
2333
  button {
2104
2334
  grid row: 1, column: column_index += 1, column_weight: 0
2105
- image File.expand_path("images/redo.png", __dir__), subsample: 32
2335
+ image File.expand_path("images/paste.png", __dir__), subsample: 32
2106
2336
 
2107
2337
  on('command') do
2108
- @text.edit_redo
2338
+ @text.text_paste
2109
2339
  end
2110
2340
  }
2111
2341
 
@@ -2114,12 +2344,22 @@ class HelloText
2114
2344
  orient 'vertical'
2115
2345
  }
2116
2346
 
2347
+
2117
2348
  button {
2118
2349
  grid row: 1, column: column_index += 1, column_weight: 0
2119
- image File.expand_path("images/picture.png", __dir__), subsample: 32
2350
+ image File.expand_path("images/undo.png", __dir__), subsample: 32
2120
2351
 
2121
2352
  on('command') do
2122
- @text.get_open_file_to_insert_image
2353
+ @text.edit_undo
2354
+ end
2355
+ }
2356
+
2357
+ button {
2358
+ grid row: 1, column: column_index += 1, column_weight: 0
2359
+ image File.expand_path("images/redo.png", __dir__), subsample: 32
2360
+
2361
+ on('command') do
2362
+ @text.edit_redo
2123
2363
  end
2124
2364
  }
2125
2365
  }
@@ -2129,8 +2369,67 @@ class HelloText
2129
2369
  wrap 'word'
2130
2370
  undo true
2131
2371
  value <=> [self, :document]
2372
+
2373
+ on('InsertMarkMoved') do
2374
+ self.font_family = @text.applied_font_format_value('family')
2375
+ self.font_size = @text.applied_font_format_value('size')
2376
+ @bold_button.default = @text.applied_font_format_value('weight') == 'bold' ? 'active' : 'normal'
2377
+ @italic_button.default = @text.applied_font_format_value('slant') == 'italic' ? 'active' : 'normal'
2378
+ @underline_button.default = @text.applied_font_format_value('underline') == true ? 'active' : 'normal'
2379
+ self.background = @text.applied_format_value('background')
2380
+ self.foreground = @text.applied_format_value('foreground')
2381
+ @justify_left_button.default = @text.applied_format_value('justify') == 'left' ? 'active' : 'normal'
2382
+ @justify_center_button.default = @text.applied_format_value('justify') == 'center' ? 'active' : 'normal'
2383
+ @justify_right_button.default = @text.applied_format_value('justify') == 'right' ? 'active' : 'normal'
2384
+ end
2385
+
2386
+ on('KeyPress') do |event|
2387
+ show_find_dialog if (event.keysym == 'f') && ((OS.mac? && event.state == 8) || (!OS.mac? && event.state == 4))
2388
+ end
2132
2389
  }
2133
- }.open
2390
+ }
2391
+ @root.open
2392
+ end
2393
+
2394
+ def show_find_dialog
2395
+ toplevel(@root) { |tl|
2396
+ title 'Find'
2397
+
2398
+ label {
2399
+ text 'Text:'
2400
+ }
2401
+ entry { |e|
2402
+ focus true
2403
+ text <=> [
2404
+ self,
2405
+ :find_text,
2406
+ after_write: lambda do
2407
+ text_index = @text.search(/#{find_text}/i, 'insert')
2408
+ unless text_index.to_s.empty?
2409
+ @text.tag_remove('sel', '1.0', 'end')
2410
+ @text.tag_add('sel', text_index, "#{text_index} + #{find_text.size} chars")
2411
+ end
2412
+ end
2413
+ ]
2414
+
2415
+ on('KeyPress') do |event|
2416
+ if event.keysym == 'Return'
2417
+ find
2418
+ elsif event.keysym == 'Escape'
2419
+ tl.grab_release
2420
+ tl.destroy
2421
+ end
2422
+ end
2423
+ }
2424
+ button {
2425
+ text 'Find'
2426
+ default 'active'
2427
+
2428
+ on('command') do
2429
+ find
2430
+ end
2431
+ }
2432
+ }
2134
2433
  end
2135
2434
  end
2136
2435
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.33
1
+ 0.0.37
data/bin/girb_runner.rb CHANGED
@@ -27,7 +27,7 @@ require_relative '../lib/glimmer-dsl-tk'
27
27
 
28
28
  include Glimmer
29
29
 
30
- GIRB_RUNNER_EXIT_FILE = "#{Etc.getpwuid.dir}/.girb_runner_exit"
30
+ GIRB_RUNNER_EXIT_FILE = "#{Dir.home}/.girb_runner_exit"
31
31
  FileUtils.rm_rf GIRB_RUNNER_EXIT_FILE
32
32
 
33
33
  @exit_method = method(:exit)