json_viewer_gtk3 0.0.2 → 0.0.3

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: 701ed09b04f65c91c410735723439f5a72f7e1e97dc219d6ea0778fbe1fa379f
4
- data.tar.gz: c6497b134d94ea1618ffb1afc34163a1589501ee2bb4db5013fde02dafb45fb0
3
+ metadata.gz: a3f0ed31efa98e74210f28622c365fde69ac46a3440c4b72c0e03316157cd749
4
+ data.tar.gz: f532776bb68b49ca8f4fcb9b446ddd37afd9c0bc41fb80b9ebd0cc1662123f43
5
5
  SHA512:
6
- metadata.gz: 5f79978c160ea41c5cd0df0251f1e415618e4f4147ac4988612bae0314d6c37dfea1bb04fa5cfd80696f9800dfe19902ac07ea9be6a4a9555facbd980ed3ae3d
7
- data.tar.gz: a893ef73596352bd31e1b988e073357aa9542e859a5a29effd1b2a329951b391e208427caa3ca8adb89ef5553615ed4af468ed1ea4fbd1e570d1d9318df005e0
6
+ metadata.gz: dcda865a7a45a49b7357ee56bcb54d1df9e13005a8cbc8503f41bc263d443a649fe660877c175e79afbc5db3353f7dc0fb258f0f4f7d646b43221daf0e478b8e
7
+ data.tar.gz: 5d5f86dbeee47cd09c457cdfb441c4a1333ba2d5e4d91eb1fc6bc0bc0ff18af9b854521f49b3a5b40d4a5b205cd1b38719104998df82095c03415909440cf742
@@ -29,7 +29,7 @@ resource = Gio::Resource.load(resource_bin)
29
29
  Gio::Resources.register(resource)
30
30
 
31
31
  app.signal_connect :activate do |application|
32
- window = JsonView::ApplicationWindow.new application
32
+ window = JsonView::ApplicationWindow.new application, ARGV
33
33
  window.present
34
34
  end
35
35
 
@@ -17,12 +17,13 @@ module JsonView
17
17
  end
18
18
  end
19
19
 
20
- def initialize(application)
20
+ def initialize(application, argv)
21
21
  super application: application
22
22
  set_title 'JsonView'
23
23
  set_icon GdkPixbuf::Pixbuf.new(
24
24
  resource: '/com/github/kojix2/jsonview/ruby.png'
25
25
  )
26
+ argv[0] && open_json(argv[0])
26
27
  end
27
28
 
28
29
  def on_open_clicked
@@ -36,6 +37,7 @@ module JsonView
36
37
  Gtk::FileFilter.new.tap do |f|
37
38
  f.name = 'Json'
38
39
  f.add_pattern('*.json')
40
+ f.add_pattern('*.JSON')
39
41
  dialog.add_filter f
40
42
  end
41
43
  Gtk::FileFilter.new.tap do |f|
@@ -57,43 +59,69 @@ module JsonView
57
59
  data = File.open(filename) do |file|
58
60
  JSON.load(file)
59
61
  end
60
- @model&.destroy
61
- @model = Gtk::TreeStore.new(String, Float)
62
+ @treemodel&.destroy
63
+ @treemodel = Gtk::TreeStore.new(String, Float, String)
62
64
  create_model(data)
63
- treeview.model = @model
65
+ treeview.model = @treemodel
64
66
 
65
67
  column = Gtk::TreeViewColumn.new(
66
68
  File.basename(filename),
67
69
  Gtk::CellRendererText.new,
68
- {
69
- text: 0,
70
- scale: 1
71
- }
70
+ { text: 0, scale: 1, foreground: 2 }
72
71
  )
73
72
  treeview.append_column(column)
74
73
  end
75
74
 
76
- def create_model(data, parent = nil, size = 1.0)
77
- parent ||= @model.append(nil)
75
+ def create_model(data, parent = nil, level = 0)
76
+ parent ||= @treemodel.append(nil)
78
77
  case data
79
78
  when Hash
80
79
  data.each do |key, value|
81
- i = @model.append(parent)
80
+ i = @treemodel.append(parent)
82
81
  i[0] = key.to_s
83
- i[1] = size
84
- create_model(value, i, size * 0.9)
82
+ i[1] = 1.0 # drate ** level
83
+ create_model(value, i, level + 1)
85
84
  end
86
85
  when Array
87
86
  data.each do |value|
88
- i = @model.append(parent)
87
+ i = @treemodel.append(parent)
89
88
  i[0] = ''
90
- i[1] = size
91
- create_model(value, i, size * 0.9)
89
+ i[1] = 1.0 # drate ** level
90
+ create_model(value, i, level + 1)
92
91
  end
93
- when String, Numeric, Integer
94
- @model.append(parent).tap do |j|
92
+ when String
93
+ level += 1
94
+ @treemodel.append(parent).tap do |j|
95
+ j[0] = data
96
+ j[1] = 1.0 # drate ** level
97
+ end
98
+ when Numeric, Integer
99
+ level += 1
100
+ @treemodel.append(parent).tap do |j|
101
+ j[0] = data.to_s
102
+ j[1] = 1.0 # drate ** level
103
+ j[2] = 'yellow'
104
+ end
105
+ when true
106
+ level += 1
107
+ @treemodel.append(parent).tap do |j|
108
+ j[0] = data.to_s
109
+ j[1] = 1.0 # drate ** level
110
+ j[2] = 'magenta'
111
+ end
112
+ when false
113
+ level += 1
114
+ @treemodel.append(parent).tap do |j|
115
+ j[0] = data.to_s
116
+ j[1] = 1.0 # drate ** level
117
+ j[2] = 'cyan'
118
+ end
119
+ else
120
+ level += 1
121
+ @treemodel.append(parent).tap do |j|
95
122
  j[0] = data.to_s
96
- j[1] = size * 0.9
123
+ j[1] = 1.0 # drate ** level
124
+ j[2] = 'lime'
97
125
  end
98
126
  end
99
127
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonView
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_viewer_gtk3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2