glimmer-dsl-swt 4.18.3.4 → 4.18.3.5

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: 63410b8b302bc061b5089d24bcadaacbd54b83bbb581ffecd0a46c7c026329c1
4
- data.tar.gz: 60da9c410a221130713e209c0e6127d3e04f17feccbcb29788c2234a90802bb9
3
+ metadata.gz: 9d3b93ed7e1bfaddf902080def3c370528f1f7d199f470e504cab6c60cc78934
4
+ data.tar.gz: 5cd60a864c6b5ba100ba5293632e7eb85411da636ef87338d4f8ef090190b726
5
5
  SHA512:
6
- metadata.gz: 81a1feac2ef1bf9c7329d26714d0d7c61b926f710a785f0b7d2e1a424b2548cf159604ada03f368996c99cb45d0834bb362a715cbfae0fa5ec1b4e5af659ee8b
7
- data.tar.gz: a4c1e06cf9aa7f3b656e9d5d22d56883f1def62865b1aa56555041c8238c07e0f333f17cd6f6108ada800e1738294f148757752e4609e1dd34dcbdc8183bd1ba
6
+ metadata.gz: a53eea373c988e58a5a5e021eeb8ba5e0be74254a53e7a50c7ab1bf716df6db9fc9ce0fed70169d88b3f6ffa54cdb39bd4ba9cdc415ae1f9feeb3980c84c9538
7
+ data.tar.gz: 5965bb2ba7ebda9858228a06dddc74309032f435b13426c9fe4922d646f2698d77f045f4025d04085775e36fc1ea5e3529b77d309776579ef084009ebfbfca1a
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.18.3.5
4
+
5
+ - Add `write_on_cancel: true` option for TableProxy#edit_table_item to make cancel behave just like save for special cases where you cannot cancel except the edit mode itself
6
+ - Make code_text custom widget support multiple code languages via `language: 'java'` option
7
+ - Make code_text custom widget support multiple themes via `theme: 'github'` option
8
+ - Hello, Code Text! Sample
9
+ - Fix issue with High Score Dialog in Tetris Sample not sorting by scores correctly (string compare instead of numeric compare) until first game is completed
10
+ - Fix issue with setting date geting rejected in `date_time` for month or day being incompatible with the year/month/day combo
11
+
3
12
  ### 4.18.3.4
4
13
 
5
14
  - Support building Image objects with the Glimmer Canvas Shape DSL
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 SWT 4.18.3.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 SWT 4.18.3.5
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -8,7 +8,7 @@
8
8
 
9
9
  **[Contributors Wanted! (Submit a Glimmer App Sample to Get Started)](#contributing)**
10
10
 
11
- [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer) is a native-GUI cross-platform desktop development library written in [JRuby](https://www.jruby.org/), an OS-threaded faster JVM version of [Ruby](https://www.ruby-lang.org/en/). [Glimmer](https://github.com/AndyObtiva/glimmer)'s main innovation is a declarative [Ruby DSL](#glimmer-dsl-syntax) that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust [Eclipse SWT library](https://www.eclipse.org/swt/). [Glimmer](https://rubygems.org/gems/glimmer) additionally innovates by having built-in [data-binding](#data-binding) support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. Not only does Glimmer provide a large set of GUI [widgets](#widgets), but it also supports drawing Canvas Graphics like [Shapes](#canvas-shape-dsl) and [Animations](#canvas-animation-dsl). To get started quickly, [Glimmer](https://rubygems.org/gems/glimmer) s [scaffolding](#scaffolding) options for [Apps](#in-production), [Gems](#custom-shell-gem), and [Custom Widgets](#custom-widgets). [Glimmer](https://rubygems.org/gems/glimmer) also includes native-executable [packaging](#packaging--distribution) support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in [Ruby](https://www.ruby-lang.org/en/) as truly native DMG/PKG/APP files on the [Mac](https://www.apple.com/ca/macos) + [App Store](https://developer.apple.com/macos/distribution/), MSI/EXE files on [Windows](https://www.microsoft.com/en-ca/windows), and [Gem Packaged Shell Scripts](#custom-shell-gem) on [Linux](https://www.linux.org/).
11
+ [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer) is a native-GUI cross-platform desktop development library written in [JRuby](https://www.jruby.org/), an OS-threaded faster JVM version of [Ruby](https://www.ruby-lang.org/en/). [Glimmer](https://github.com/AndyObtiva/glimmer)'s main innovation is a declarative [Ruby DSL](#glimmer-dsl-syntax) that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust [Eclipse SWT library](https://www.eclipse.org/swt/). [Glimmer](https://rubygems.org/gems/glimmer) additionally innovates by having built-in [data-binding](#data-binding) support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. Not only does Glimmer provide a large set of GUI [widgets](#widgets), but it also supports drawing Canvas Graphics like [Shapes](#canvas-shape-dsl) and [Animations](#canvas-animation-dsl). To get started quickly, [Glimmer](https://rubygems.org/gems/glimmer) offers [scaffolding](#scaffolding) options for [Apps](#in-production), [Gems](#custom-shell-gem), and [Custom Widgets](#custom-widgets). [Glimmer](https://rubygems.org/gems/glimmer) also includes native-executable [packaging](#packaging--distribution) support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in [Ruby](https://www.ruby-lang.org/en/) as truly native DMG/PKG/APP files on the [Mac](https://www.apple.com/ca/macos) + [App Store](https://developer.apple.com/macos/distribution/), MSI/EXE files on [Windows](https://www.microsoft.com/en-ca/windows), and [Gem Packaged Shell Scripts](#custom-shell-gem) on [Linux](https://www.linux.org/).
12
12
 
13
13
  [Glimmer receives two updates per month](https://rubygems.org/gems/glimmer-dsl-swt/versions). You can trust [Glimmer](https://rubygems.org/gems/glimmer) with your Ruby desktop GUI development needs. Please make [Glimmer](https://rubygems.org/gems/glimmer) even better by providing feedback and [contributing](#contributing) when possible.
14
14
 
@@ -493,7 +493,7 @@ jgem install glimmer-dsl-swt
493
493
 
494
494
  Or this command if you want a specific version:
495
495
  ```
496
- jgem install glimmer-dsl-swt -v 4.18.3.4
496
+ jgem install glimmer-dsl-swt -v 4.18.3.5
497
497
 
498
498
 
499
499
  ```
@@ -513,7 +513,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
513
513
 
514
514
  Add the following to `Gemfile`:
515
515
  ```
516
- gem 'glimmer-dsl-swt', '~> 4.18.3.4
516
+ gem 'glimmer-dsl-swt', '~> 4.18.3.5
517
517
  '
518
518
  ```
519
519
 
@@ -572,7 +572,7 @@ bin/glimmer samples
572
572
  Below are the full usage instructions that come up when running `glimmer` without args.
573
573
 
574
574
  ```
575
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.3.4
575
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.3.5
576
576
 
577
577
 
578
578
 
@@ -1053,7 +1053,7 @@ Output:
1053
1053
 
1054
1054
  Css glimmer-dsl-css 1.1.0 AndyMaleh Glimmer DSL for CSS
1055
1055
  Opal glimmer-dsl-opal 0.10.2 AndyMaleh Glimmer DSL for Opal
1056
- Swt glimmer-dsl-swt 4.18.3.4
1056
+ Swt glimmer-dsl-swt 4.18.3.5
1057
1057
 
1058
1058
  AndyMaleh Glimmer DSL for SWT
1059
1059
  Tk glimmer-dsl-tk 0.0.6 AndyMaleh Glimmer DSL for Tk
@@ -4017,6 +4017,225 @@ Glimmer Meta-Sample Code Example:
4017
4017
 
4018
4018
  To use, simply use `code_text` in place of the `text` or `styled_text` widget. If you set its `text` value to Ruby code, it automatically styles it with syntax highlighting.
4019
4019
 
4020
+ ##### Options
4021
+
4022
+ **theme**
4023
+ (default: 'glimmer')
4024
+
4025
+ Changes syntax color highlighting theme. Can be one of the following:
4026
+ - glimmer
4027
+ - github
4028
+ - pastie
4029
+
4030
+ **language**
4031
+ (default: `'ruby'`)
4032
+
4033
+ Sets the code language, which can be one of the following supported rouge gem languages:
4034
+ - abap
4035
+ - actionscript
4036
+ - ada
4037
+ - apache
4038
+ - apex
4039
+ - apiblueprint
4040
+ - apple_script
4041
+ - armasm
4042
+ - augeas
4043
+ - awk
4044
+ - batchfile
4045
+ - bbcbasic
4046
+ - bibtex
4047
+ - biml
4048
+ - bpf
4049
+ - brainfuck
4050
+ - brightscript
4051
+ - bsl
4052
+ - c
4053
+ - ceylon
4054
+ - cfscript
4055
+ - clean
4056
+ - clojure
4057
+ - cmake
4058
+ - cmhg
4059
+ - coffeescript
4060
+ - common_lisp
4061
+ - conf
4062
+ - console
4063
+ - coq
4064
+ - cpp
4065
+ - crystal
4066
+ - csharp
4067
+ - css
4068
+ - csvs
4069
+ - cuda
4070
+ - cypher
4071
+ - cython
4072
+ - d
4073
+ - dart
4074
+ - datastudio
4075
+ - diff
4076
+ - digdag
4077
+ - docker
4078
+ - dot
4079
+ - ecl
4080
+ - eex
4081
+ - eiffel
4082
+ - elixir
4083
+ - elm
4084
+ - email
4085
+ - epp
4086
+ - erb
4087
+ - erlang
4088
+ - escape
4089
+ - factor
4090
+ - fortran
4091
+ - freefem
4092
+ - fsharp
4093
+ - gdscript
4094
+ - ghc_cmm
4095
+ - ghc_core
4096
+ - gherkin
4097
+ - glsl
4098
+ - go
4099
+ - gradle
4100
+ - graphql
4101
+ - groovy
4102
+ - hack
4103
+ - haml
4104
+ - handlebars
4105
+ - haskell
4106
+ - haxe
4107
+ - hcl
4108
+ - hlsl
4109
+ - hocon
4110
+ - hql
4111
+ - html
4112
+ - http
4113
+ - hylang
4114
+ - idlang
4115
+ - igorpro
4116
+ - ini
4117
+ - io
4118
+ - irb
4119
+ - isbl
4120
+ - j
4121
+ - janet
4122
+ - java
4123
+ - javascript
4124
+ - jinja
4125
+ - jsl
4126
+ - json
4127
+ - json_doc
4128
+ - jsonnet
4129
+ - jsp
4130
+ - jsx
4131
+ - julia
4132
+ - kotlin
4133
+ - lasso
4134
+ - liquid
4135
+ - literate_coffeescript
4136
+ - literate_haskell
4137
+ - livescript
4138
+ - llvm
4139
+ - lua
4140
+ - lustre
4141
+ - lutin
4142
+ - m68k
4143
+ - magik
4144
+ - make
4145
+ - markdown
4146
+ - mason
4147
+ - mathematica
4148
+ - matlab
4149
+ - minizinc
4150
+ - moonscript
4151
+ - mosel
4152
+ - msgtrans
4153
+ - mxml
4154
+ - nasm
4155
+ - nesasm
4156
+ - nginx
4157
+ - nim
4158
+ - nix
4159
+ - objective_c
4160
+ - objective_cpp
4161
+ - ocaml
4162
+ - ocl
4163
+ - openedge
4164
+ - opentype_feature_file
4165
+ - pascal
4166
+ - perl
4167
+ - php
4168
+ - plain_text
4169
+ - plist
4170
+ - pony
4171
+ - postscript
4172
+ - powershell
4173
+ - praat
4174
+ - prolog
4175
+ - prometheus
4176
+ - properties
4177
+ - protobuf
4178
+ - puppet
4179
+ - python
4180
+ - q
4181
+ - qml
4182
+ - r
4183
+ - racket
4184
+ - reasonml
4185
+ - rego
4186
+ - rescript
4187
+ - robot_framework
4188
+ - ruby
4189
+ - rust
4190
+ - sas
4191
+ - sass
4192
+ - scala
4193
+ - scheme
4194
+ - scss
4195
+ - sed
4196
+ - shell
4197
+ - sieve
4198
+ - slice
4199
+ - slim
4200
+ - smalltalk
4201
+ - smarty
4202
+ - sml
4203
+ - solidity
4204
+ - sparql
4205
+ - sqf
4206
+ - sql
4207
+ - ssh
4208
+ - supercollider
4209
+ - swift
4210
+ - systemd
4211
+ - tap
4212
+ - tcl
4213
+ - terraform
4214
+ - tex
4215
+ - toml
4216
+ - tsx
4217
+ - ttcn3
4218
+ - tulip
4219
+ - turtle
4220
+ - twig
4221
+ - typescript
4222
+ - vala
4223
+ - varnish
4224
+ - vb
4225
+ - velocity
4226
+ - verilog
4227
+ - vhdl
4228
+ - viml
4229
+ - vue
4230
+ - wollok
4231
+ - xml
4232
+ - xojo
4233
+ - xpath
4234
+ - xquery
4235
+ - yaml
4236
+ - yang
4237
+ - zig
4238
+
4020
4239
  #### Video Widget
4021
4240
 
4022
4241
  [![Video Widget](images/glimmer-video-widget.png)](https://github.com/AndyObtiva/glimmer-cw-video)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.18.3.4
1
+ 4.18.3.5
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-swt 4.18.3.4 ruby lib
5
+ # stub: glimmer-dsl-swt 4.18.3.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-swt".freeze
9
- s.version = "4.18.3.4"
9
+ s.version = "4.18.3.5"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2021-01-30"
14
+ s.date = "2021-02-01"
15
15
  s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) is a native-GUI cross-platform desktop development library written in JRuby, an OS-threaded faster JVM version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. Not only does Glimmer provide a large set of GUI widgets, but it also supports drawing Canvas Graphics like Shapes and Animations. To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets. Glimmer also includes native-executable packaging support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["glimmer".freeze, "girb".freeze]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "icons/scaffold_app.png",
35
35
  "lib/ext/glimmer.rb",
36
36
  "lib/ext/glimmer/config.rb",
37
+ "lib/ext/rouge/themes/glimmer.rb",
37
38
  "lib/glimmer-dsl-swt.rb",
38
39
  "lib/glimmer/Rakefile",
39
40
  "lib/glimmer/data_binding/list_selection_binding.rb",
@@ -156,6 +157,7 @@ Gem::Specification.new do |s|
156
157
  "samples/hello/hello_canvas_transform.rb",
157
158
  "samples/hello/hello_checkbox.rb",
158
159
  "samples/hello/hello_checkbox_group.rb",
160
+ "samples/hello/hello_code_text.rb",
159
161
  "samples/hello/hello_combo.rb",
160
162
  "samples/hello/hello_computed.rb",
161
163
  "samples/hello/hello_computed/contact.rb",
@@ -0,0 +1,29 @@
1
+ module Rouge
2
+ module Themes
3
+ # A port of the pastie style from Pygments.
4
+ # See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/pastie.py
5
+ class Glimmer < Github
6
+ name 'glimmer'
7
+ style Comment::Single, fg: [106,115,125], italic: true # Also, Comments
8
+ style Keyword::Pseudo, fg: [:dark_red]
9
+ style Keyword, fg: [:blue]
10
+ style Literal::String::Single, fg: [106,115,125] # Also, Comments
11
+ style Literal::String::Double, fg: [0,92,197]
12
+ style Literal::String::Escape, fg: [:red]
13
+ style Literal::Number::Integer, fg: [:blue]
14
+ style Literal::String::Interpol, fg: [:blue]
15
+ style Literal::String::Symbol, fg: [:dark_green]
16
+ style Literal::String, fg: [:dark_blue]
17
+ style Name::Builtin, fg: [215,58,73]
18
+ style Name::Class, fg: [3,47,98]
19
+ style Name::Namespace, fg: [3,47,98]
20
+ style Name::Constant, fg: [0,92,197]
21
+ style Name::Function, fg: [:blue]
22
+ style Name::Variable::Instance, fg: [227,98,9]
23
+ style Name, fg: [111,66,193] #purple
24
+ style Operator, fg: [:red]
25
+ style Punctuation, fg: [:blue]
26
+ style Text, fg: [75, 75, 75]
27
+ end
28
+ end
29
+ end
@@ -34,7 +34,6 @@ require 'glimmer'
34
34
  require 'logging'
35
35
  require 'nested_inherited_jruby_include_package'
36
36
  require 'super_module'
37
- require 'rouge'
38
37
  require 'date'
39
38
  require 'facets/string/capitalized'
40
39
  require 'facets/hash/symbolize_keys'
@@ -7,36 +7,59 @@ module Glimmer
7
7
  class CodeText
8
8
  include Glimmer::UI::CustomWidget
9
9
 
10
- SYNTAX_COLOR_MAP = {
11
- Builtin: [215,58,73],
12
- Class: [3,47,98],
13
- Constant: [0,92,197],
14
- Double: [0,92,197],
15
- Escape: [:red],
16
- Function: [:blue],
17
- Instance: [227,98,9],
18
- Integer: [:blue],
19
- Interpol: [:blue],
20
- Keyword: [:blue],
21
- Name: [111,66,193], #purple
22
- Operator: [:red],
23
- Pseudo: [:dark_red],
24
- Punctuation: [:blue],
25
- Single: [106,115,125], # Also, Comments
26
- Symbol: [:dark_green],
27
- Text: [75, 75, 75],
28
- }
10
+ class << self
11
+ def languages
12
+ require 'rouge'
13
+ Rouge::Lexer.all.map {|lexer| lexer.tag}.sort
14
+ end
15
+
16
+ def lexers
17
+ require 'rouge'
18
+ Rouge::Lexer.all.sort_by(&:title)
19
+ end
20
+ end
21
+
22
+ REGEX_COLOR_HEX6 = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/
29
23
 
30
- # TODO support `option :language`
31
24
  # TODO support auto language detection
25
+ # TODO support end of line via CMD+E and beginning of line via CMD+A
26
+ # TODO support select all via CMD+A
27
+
28
+ option :language, default: 'ruby'
29
+ # TODO consider supporting data-binding of language
30
+ # TODO support switcher of language that automatically updates the lexer
31
+ # TODO support method for redrawing the syntax highlighting
32
+ option :theme, default: 'glimmer'
33
+ # option :lines, default: false
32
34
 
33
- def text=(value)
34
- swt_widget&.text = value
35
- end
35
+ # attr_accessor :code_text_widget_text, :code_text_widget_top_pixel
36
+ # attr_reader :styled_text_proxy
36
37
 
37
- def text
38
- swt_widget&.text
39
- end
38
+
39
+
40
+ # def text=(value)
41
+ # if lines
42
+ # @styled_text_proxy&.swt_widget&.text = value
43
+ # else
44
+ # super
45
+ # end
46
+ # end
47
+
48
+ # def text(*args)
49
+ # if lines
50
+ # @styled_text_proxy&.swt_widget&.text
51
+ # else
52
+ # super
53
+ # end
54
+ # end
55
+
56
+ # def lines_width
57
+ # if lines == true
58
+ # 4
59
+ # elsif lines.is_a?(Hash)
60
+ # lines[:width]
61
+ # end
62
+ # end
40
63
 
41
64
  def syntax_highlighting(text)
42
65
  return [] if text.to_s.strip.empty?
@@ -56,16 +79,68 @@ module Glimmer
56
79
 
57
80
  def lexer
58
81
  # TODO Try to use Rouge::Lexer.find_fancy('guess', code) in the future to guess the language or otherwise detect it from file extension
59
- @lexer ||= Rouge::Lexer.find_fancy('ruby')
82
+ @lexer ||= Rouge::Lexer.find_fancy(language)
60
83
  end
61
84
 
62
85
  before_body {
86
+ require 'rouge'
87
+ require 'ext/rouge/themes/glimmer'
63
88
  @swt_style = swt_style == 0 ? [:border, :multi, :v_scroll, :h_scroll] : swt_style
64
89
  @font_name = display.get_font_list(nil, true).map(&:name).include?('Consolas') ? 'Consolas' : 'Courier'
65
90
  }
66
91
 
67
92
  body {
68
- styled_text(swt_style) {
93
+ # TODO enable this once fully implemented
94
+ # if lines
95
+ # composite {
96
+ # grid_layout(2, false)
97
+ # layout_data :fill, :fill, true, true
98
+ # @line_numbers_text = styled_text(:multi, :border) {
99
+ # layout_data(:right, :fill, false, true)
100
+ # text ' 1'
101
+ # line_count = code_text_widget_text.to_s.split("\n").count
102
+ # line_count = 1 if line_count == 0
103
+ # lines_text_size = [line_count.to_s.size, 4].max
104
+ # text line_count.times.map {|n| (' ' * (lines_text_size - (n+1).to_s.size)) + (n+1).to_s }.join("\n")
105
+ # text bind(self, :code_text_widget_text, read_only: true) { |text_value|
106
+ # line_count = text_value.to_s.split("\n").count
107
+ # line_count = 1 if line_count == 0
108
+ # lines_text_size = [line_count.to_s.size, 4].max
109
+ # line_count.times.map {|n| (' ' * (lines_text_size - (n+1).to_s.size)) + (n+1).to_s }.join("\n")
110
+ # }
111
+ # top_pixel bind(self, :code_text_widget_top_pixel, read_only: true)
112
+ # font name: @font_name, height: OS.mac? ? 15 : 12
113
+ # background color(:widget_background)
114
+ # foreground :dark_blue
115
+ # top_margin 5
116
+ # right_margin 5
117
+ # bottom_margin 5
118
+ # left_margin 5
119
+ # editable false
120
+ # caret nil
121
+ # on_focus_gained {
122
+ # @styled_text_proxy&.swt_widget.setFocus
123
+ # }
124
+ # on_key_pressed {
125
+ # @styled_text_proxy&.swt_widget.setFocus
126
+ # }
127
+ # on_mouse_up {
128
+ # @styled_text_proxy&.swt_widget.setFocus
129
+ # }
130
+ # }
131
+ #
132
+ # code_text_widget
133
+ # }
134
+ # else
135
+ code_text_widget
136
+ # end
137
+ }
138
+
139
+ def code_text_widget
140
+ @styled_text_proxy = styled_text(swt_style) {
141
+ # layout_data :fill, :fill, true, true if lines
142
+ # text bind(self, :code_text_widget_text) if lines
143
+ # top_pixel bind(self, :code_text_widget_top_pixel) if lines
69
144
  font name: @font_name, height: 15
70
145
  foreground rgb(75, 75, 75)
71
146
  left_margin 5
@@ -88,18 +163,38 @@ module Glimmer
88
163
  }
89
164
 
90
165
  on_line_get_style { |line_style_event|
91
- styles = []
92
- syntax_highlighting(line_style_event.lineText).to_a.each do |token_hash|
93
- start_index = token_hash[:token_index]
94
- size = token_hash[:token_text].size
95
- token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
96
- token_color = color(*token_color).swt_color
97
- styles << StyleRange.new(line_style_event.lineOffset + start_index, size, token_color, nil)
166
+ begin
167
+ styles = []
168
+ style_data = nil
169
+ syntax_highlighting(line_style_event.lineText).to_a.each do |token_hash|
170
+ start_index = token_hash[:token_index]
171
+ size = token_hash[:token_text].size
172
+ style_data = Rouge::Theme.find(theme).new.style_for(token_hash[:token_type])
173
+ foreground_color = hex_color_to_swt_color(style_data[:fg], [:black])
174
+ background_color = hex_color_to_swt_color(style_data[:bg], [:white])
175
+ font_styles = []
176
+ font_styles << :bold if style_data[:bold]
177
+ font_styles << :italic if style_data[:italic]
178
+ font_style = SWTProxy[*font_styles]
179
+ styles << StyleRange.new(line_style_event.lineOffset + start_index, size, foreground_color, background_color, font_style)
180
+ end
181
+ line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
182
+ rescue => e
183
+ Glimmer::Config.logger.error {"Error encountered with style data: #{style_data}"}
184
+ Glimmer::Config.logger.error {e.message}
185
+ Glimmer::Config.logger.error {e.full_message}
98
186
  end
99
- line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
100
187
  }
101
188
  }
102
- }
189
+ end
190
+
191
+ def hex_color_to_swt_color(color_data, default_color)
192
+ color_data = "##{color_data.chars.drop(1).map {|c| c*2}.join}" if color_data.is_a?(String) && color_data.start_with?('#') && color_data&.size == 4
193
+ color_data = color_data.match(REGEX_COLOR_HEX6).to_a.drop(1).map {|c| "0x#{c}".hex}.to_a if color_data.is_a?(String) && color_data.start_with?('#')
194
+ color_data = [color_data] unless color_data.nil? || color_data.empty? || color_data.is_a?(Array)
195
+ color_data = default_color if color_data.nil? || color_data.empty?
196
+ color(*color_data).swt_color
197
+ end
103
198
  end
104
199
  end
105
200
  end
@@ -43,9 +43,7 @@ module Glimmer
43
43
  end
44
44
 
45
45
  def date=(date_value)
46
- self.year = date_value.year
47
- self.month = date_value.month
48
- self.day = date_value.day
46
+ swt_widget.setDate(date_value.year, date_value.month - 1, date_value.day)
49
47
  end
50
48
 
51
49
  def time
@@ -43,6 +43,7 @@ module Glimmer
43
43
 
44
44
  attr_reader :widget_proxy, :swt_font, :font_properties
45
45
 
46
+
46
47
  # Builds a new font proxy from passed in widget_proxy and font_properties hash,
47
48
  #
48
49
  # It begins with existing SWT widget font and amends it with font properties.
@@ -457,7 +457,7 @@ module Glimmer
457
457
  edit_table_item(swt_widget.getSelection.first, column_index, before_write: before_write, after_write: after_write, after_cancel: after_cancel)
458
458
  end
459
459
 
460
- def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil)
460
+ def edit_table_item(table_item, column_index, before_write: nil, after_write: nil, after_cancel: nil, write_on_cancel: false)
461
461
  return if table_item.nil?
462
462
  model = table_item.data
463
463
  property = column_properties[column_index]
@@ -476,18 +476,22 @@ module Glimmer
476
476
  widget_value_property = TableProxy::editors.symbolize_keys[editor_widget][:widget_value_property]
477
477
 
478
478
  @cancel_edit = lambda do |event=nil|
479
- @cancel_in_progress = true
480
- @table_editor_widget_proxy&.swt_widget&.dispose
481
- @table_editor_widget_proxy = nil
482
- if after_cancel&.arity == 0
483
- after_cancel&.call
479
+ if write_on_cancel
480
+ @finish_edit.call(event)
484
481
  else
485
- after_cancel&.call(table_item)
482
+ @cancel_in_progress = true
483
+ @table_editor_widget_proxy&.swt_widget&.dispose
484
+ @table_editor_widget_proxy = nil
485
+ if after_cancel&.arity == 0
486
+ after_cancel&.call
487
+ else
488
+ after_cancel&.call(table_item)
489
+ end
490
+ @edit_in_progress = false
491
+ @cancel_in_progress = false
492
+ @cancel_edit = nil
493
+ @edit_mode = false
486
494
  end
487
- @edit_in_progress = false
488
- @cancel_in_progress = false
489
- @cancel_edit = nil
490
- @edit_mode = false
491
495
  end
492
496
 
493
497
  @finish_edit = lambda do |event=nil|
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'fileutils'
23
23
  require 'etc'
24
+ require 'json'
24
25
  require 'glimmer/data_binding/observer'
25
26
  require 'glimmer/config'
26
27
 
@@ -21,6 +21,19 @@
21
21
 
22
22
  class Tetris
23
23
  module Model
24
- PastGame = Struct.new(:name, :score, :lines, :level)
24
+ class PastGame
25
+ attr_accessor :name, :score, :lines, :level
26
+
27
+ def initialize(name, score, lines, level)
28
+ @name = name
29
+ @score = score.to_i
30
+ @lines = lines.to_i
31
+ @level = level.to_i
32
+ end
33
+
34
+ def to_a
35
+ [@name, @score, @lines, @level]
36
+ end
37
+ end
25
38
  end
26
39
  end
@@ -99,13 +99,11 @@ class Tetris
99
99
  @high_score_table.edit_table_item(
100
100
  @high_score_table.items.first, # row item
101
101
  0, # column
102
+ write_on_cancel: true,
102
103
  after_write: -> {
103
104
  game.save_high_scores!
104
105
  @play_close_button.set_focus
105
106
  },
106
- after_cancel: -> {
107
- @play_close_button.set_focus
108
- },
109
107
  )
110
108
  end
111
109
  }
@@ -0,0 +1,84 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ include Glimmer
23
+
24
+ shell {
25
+ minimum_size 640, 480
26
+ text 'Hello, Code Text!'
27
+
28
+ tab_folder {
29
+ tab_item {
30
+ fill_layout
31
+ text 'ruby (glimmer theme)'
32
+ code_text(language: 'ruby', theme: 'glimmer') {
33
+ text <<~CODE
34
+ greeting = 'Hello, World!'
35
+
36
+ include Glimmer
37
+
38
+ shell {
39
+ text 'Glimmer'
40
+
41
+ label {
42
+ text greeting
43
+ font height: 30, style: :bold
44
+ }
45
+ }
46
+ CODE
47
+ }
48
+ }
49
+ tab_item {
50
+ fill_layout
51
+ text 'html (github theme)'
52
+ code_text(language: 'html', theme: 'github') {
53
+ text <<~CODE
54
+ <html>
55
+ <body>
56
+ <section class="accordion">
57
+ <form method="post" id="name">
58
+ <label for="name">
59
+ Name
60
+ </label>
61
+ <input name="name" type="text" />
62
+ <input type="submit" />
63
+ </form>
64
+ </section>
65
+ </body>
66
+ </html>
67
+ CODE
68
+ }
69
+ }
70
+ tab_item {
71
+ fill_layout
72
+ text 'javascript (pastie theme)'
73
+ code_text(language: 'javascript', theme: 'pastie') {
74
+ text <<~CODE
75
+ function helloWorld(greeting) {
76
+ alert(greeting);
77
+ }
78
+ var greetingString = 'Hello, World!';
79
+ helloWorld(greetingString);
80
+ CODE
81
+ }
82
+ }
83
+ }
84
+ }.open
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.18.3.4
4
+ version: 4.18.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-30 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -367,6 +367,7 @@ files:
367
367
  - icons/scaffold_app.png
368
368
  - lib/ext/glimmer.rb
369
369
  - lib/ext/glimmer/config.rb
370
+ - lib/ext/rouge/themes/glimmer.rb
370
371
  - lib/glimmer-dsl-swt.rb
371
372
  - lib/glimmer/Rakefile
372
373
  - lib/glimmer/data_binding/list_selection_binding.rb
@@ -489,6 +490,7 @@ files:
489
490
  - samples/hello/hello_canvas_transform.rb
490
491
  - samples/hello/hello_checkbox.rb
491
492
  - samples/hello/hello_checkbox_group.rb
493
+ - samples/hello/hello_code_text.rb
492
494
  - samples/hello/hello_combo.rb
493
495
  - samples/hello/hello_computed.rb
494
496
  - samples/hello/hello_computed/contact.rb