groonga-database-viewer-gtk 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
  SHA1:
3
- metadata.gz: 9a123ff921e425f0c0c97ba55f8f92c05c04d45b
4
- data.tar.gz: 7aafad21070d426840271ffb2621641f10e1d172
3
+ metadata.gz: 3bca21aff2cea5ff6789eae7b8dd443ceae273ae
4
+ data.tar.gz: eac6de8b2a3c054441308542d08dc69599315d89
5
5
  SHA512:
6
- metadata.gz: 305720b3522cc67da8a962388a9aafd0afe607b23abcaaeed99d0f3525c780bf4d3a4b7bcaeb5a7733e868692541fc009c9875a56bd25766c577abad6916b7a2
7
- data.tar.gz: f3ca5901a8172848aa7e9f37e2cc4c01f57b055f33f4715e78ecc4038c393e35c290c1cdc92cbfb637eee559ad35e222d434aad0cffe24b48c4cd3a51bd6fcf5
6
+ metadata.gz: 7528a703a8bdb5b79771b8509841c8cab5e47be73dbe0eba889747a21336614f2ea67d26ff5dfeed0903774194f5f7947c538f3f48d15342e53a4121ffb4c57d
7
+ data.tar.gz: 662cdca9981f7f8496cca5f7c4cb30418b4602e7bc43bfcbb9922cf5883ea7f102f52b8af918dd1607f7c616506e7254aca5014bfa27ee54d510432b48ea3c16
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.3: 2014-12-07
4
+
5
+ ### Changes
6
+
7
+ * Improvements
8
+ * Add help bar
9
+ * Support to copy selected record of JSON to clipboard
10
+ * Add --wrap_width option
11
+ * Add tooltip
12
+
3
13
  ## 0.0.2: 2014-10-01
4
14
 
5
15
  ### Changes
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # README
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/groonga-database-viewer-gtk.svg)](http://badge.fury.io/rb/groonga-database-viewer-gtk)
3
4
  [![Build Status](https://travis-ci.org/myokoym/groonga-database-viewer-gtk.png?branch=master)](https://travis-ci.org/myokoym/groonga-database-viewer-gtk)
4
5
 
5
6
  ## Name
@@ -22,6 +23,16 @@ a graphical database viewer for [Groonga][] by [GTK+][] with [Ruby][].
22
23
 
23
24
  $ groonga-database-viewer-gtk DB_PATH
24
25
 
26
+ ### Options
27
+
28
+ $ groonga-database-viewer-gtk -h
29
+ Usage: groonga-database-viewer-gtk [OPTIONS] DB_PATH
30
+ --wrap_width=WIDTH Set wrap width to columns
31
+
32
+ ### For example
33
+
34
+ $ groonga-database-viewer-gtk --wrap_width=320 ~/.milkode/db/milkode.db
35
+
25
36
  ## Authors
26
37
 
27
38
  * Masafumi Yokoyama `<myokoym@gmail.com>`
@@ -16,6 +16,19 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
+ require "optparse"
20
+ require "groonga/database-viewer-gtk/version"
19
21
  require "groonga/database-viewer-gtk/window"
20
22
 
21
- Groonga::DatabaseViewerGtk::Window.new(ARGV[0]).run
23
+ usage = "Usage: groonga-database-viewer-gtk [OPTIONS] DB_PATH"
24
+ parser = OptionParser.new(usage)
25
+ parser.version = Groonga::DatabaseViewerGtk::VERSION
26
+
27
+ options = {}
28
+ parser.on("--wrap_width=WIDTH",
29
+ "Set wrap width to columns", Integer) do |width|
30
+ options[:wrap_width] = width
31
+ end
32
+ parser.parse!(ARGV)
33
+
34
+ Groonga::DatabaseViewerGtk::Window.new(ARGV[0], options).run
@@ -46,6 +46,7 @@ Gem::Specification.new do |spec|
46
46
 
47
47
  spec.add_runtime_dependency("rroonga")
48
48
  spec.add_runtime_dependency("gtk2")
49
+ spec.add_runtime_dependency("json")
49
50
 
50
51
  spec.add_development_dependency("test-unit", ">= 3.0.0")
51
52
  spec.add_development_dependency("test-unit-notify")
@@ -0,0 +1,44 @@
1
+ # Copyright (C) 2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "gtk2"
18
+
19
+ module Groonga
20
+ module DatabaseViewerGtk
21
+ class Clipboard
22
+ class << self
23
+ def copy_to_clipboard(text)
24
+ if /darwin/ =~ RUBY_PLATFORM
25
+ require "tempfile"
26
+ Tempfile.open(["clipcellar", "w"]) do |file|
27
+ text.each_line do |line|
28
+ file.puts(line)
29
+ end
30
+ file.flush
31
+ system("pbcopy < #{file.path}")
32
+ end
33
+ else
34
+ clipboard.text = text
35
+ end
36
+ end
37
+
38
+ def clipboard
39
+ Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -16,6 +16,8 @@
16
16
 
17
17
  require "groonga"
18
18
  require "gtk2"
19
+ require "cgi"
20
+ require "json"
19
21
 
20
22
  module Groonga
21
23
  module DatabaseViewerGtk
@@ -26,9 +28,11 @@ module Groonga
26
28
  attr_reader :updated
27
29
  attr_reader :grn_table
28
30
 
29
- def initialize(grn_table, db_path)
31
+ def initialize(grn_table, db_path, options={})
30
32
  super()
31
33
  @grn_table = grn_table
34
+ @tooltip_column_index = @grn_table.columns.size + 2
35
+ @wrap_width = options[:wrap_width]
32
36
  @db_path = db_path
33
37
  @updated = false
34
38
  @threads = []
@@ -40,6 +44,16 @@ module Groonga
40
44
  create_tree_view
41
45
  end
42
46
 
47
+ def selected_text
48
+ return nil unless selected_iter
49
+ escaped_text = selected_iter.get_value(@tooltip_column_index)
50
+ CGI.unescapeHTML(escaped_text)
51
+ end
52
+
53
+ def selected_iter
54
+ selection.selected
55
+ end
56
+
43
57
  def create_tree_view
44
58
  self.rules_hint = true
45
59
 
@@ -59,6 +73,7 @@ module Groonga
59
73
  append_column(gtk_column)
60
74
 
61
75
  renderer = Gtk::CellRendererText.new
76
+ renderer.wrap_width = @wrap_width if @wrap_width
62
77
  gtk_column.pack_start(renderer, :expand => false)
63
78
  gtk_column.add_attribute(renderer, :text, index)
64
79
  end
@@ -75,9 +90,11 @@ module Groonga
75
90
  end
76
91
  column_types.unshift(String) # _key
77
92
  column_types.unshift(Integer) # _id
93
+ column_types.push(String) # TOOLTIP
78
94
 
79
95
  model = Gtk::ListStore.new(*column_types)
80
96
  self.model = model
97
+ self.tooltip_column = @tooltip_column_index
81
98
 
82
99
  thread = Thread.new do
83
100
  each_records(limit, query).each do |grn_record|
@@ -90,21 +107,29 @@ module Groonga
90
107
  end
91
108
 
92
109
  def load_record(model, grn_record)
110
+ tooltips = {}
93
111
  iter = model.append
94
112
  iter.set_value(ID_COLUMN_INDEX, grn_record._id)
95
- iter.set_value(KEY_COLUMN_INDEX, grn_record._key) if grn_record.respond_to?(:_key)
113
+ tooltips["_id"] = grn_record._id
114
+ if grn_record.respond_to?(:_key)
115
+ iter.set_value(KEY_COLUMN_INDEX, grn_record._key)
116
+ tooltips["_key"] = grn_record._key
117
+ end
96
118
  @grn_table.columns.each_with_index do |grn_column, i|
97
- value = grn_record[grn_column.local_name]
98
- iter.set_value(i + 2, value.to_s)
119
+ value = nil
99
120
  if grn_column.index?
100
121
  ids = grn_column.search(grn_record._id).records.collect {|record| record._id}
101
122
  value = "#{ids.size}, #{ids.to_s}"
102
123
  else
103
124
  value = grn_record[grn_column.local_name].to_s
104
125
  end
126
+ tooltips[grn_column.local_name] = value
105
127
  iter.set_value(2 + i, value)
106
128
  GC.start if i % 100 == 0
107
129
  end
130
+ tooltip_json = tooltips.to_json
131
+ escaped_tooltip_json = CGI.escapeHTML(tooltip_json)
132
+ iter.set_value(@tooltip_column_index, escaped_tooltip_json)
108
133
  end
109
134
 
110
135
  def each_records(limit, query=nil)
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  module DatabaseViewerGtk
19
- VERSION = "0.0.2"
19
+ VERSION = "0.0.3"
20
20
  end
21
21
  end
@@ -18,13 +18,14 @@ require "groonga"
18
18
  require "gtk2"
19
19
 
20
20
  require "groonga/database-viewer-gtk/table"
21
+ require "groonga/database-viewer-gtk/clipboard"
21
22
 
22
23
  module Groonga
23
24
  module DatabaseViewerGtk
24
25
  class Window < Gtk::Window
25
26
  RAW_QUERY_MODE = "--query"
26
27
 
27
- def initialize(db_path)
28
+ def initialize(db_path, options={})
28
29
  super()
29
30
  self.title = db_path
30
31
  set_default_size(640, 480)
@@ -40,8 +41,12 @@ module Groonga
40
41
  search_hbox = create_search_hbox
41
42
  vbox.pack_start(search_hbox, false, false, 4)
42
43
 
43
- @notebook = create_notebook
44
+ @notebook = create_notebook(options)
44
45
  vbox.pack_start(@notebook, true, true, 0)
46
+
47
+ label = Gtk::Label.new
48
+ label.text = "Double Click or Press Return: Copy to Clipboard"
49
+ vbox.pack_end(label, false, false, 0)
45
50
  end
46
51
 
47
52
  def run
@@ -136,7 +141,7 @@ module Groonga
136
141
  end
137
142
  end
138
143
 
139
- def create_notebook
144
+ def create_notebook(options)
140
145
  notebook = Gtk::Notebook.new
141
146
 
142
147
  #label = Gtk::Label.new("Groonga")
@@ -146,9 +151,14 @@ module Groonga
146
151
  scrolled_window = Gtk::ScrolledWindow.new
147
152
  scrolled_window.set_policy(:automatic, :automatic)
148
153
 
149
- table = Table.new(grn_table, @grn_database.path)
154
+ table = Table.new(grn_table, @grn_database.path, options)
150
155
  scrolled_window.add(table)
151
156
 
157
+ table.signal_connect("row-activated") do |tree_view, path, column|
158
+ Clipboard.copy_to_clipboard(table.selected_text)
159
+ end
160
+
161
+
152
162
  label = Gtk::Label.new(grn_table.name)
153
163
  notebook.append_page(scrolled_window, label)
154
164
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-database-viewer-gtk
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
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: test-unit
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +123,7 @@ files:
109
123
  - bin/groonga-database-viewer-gtk
110
124
  - groonga-database-viewer-gtk.gemspec
111
125
  - lib/groonga/database-viewer-gtk.rb
126
+ - lib/groonga/database-viewer-gtk/clipboard.rb
112
127
  - lib/groonga/database-viewer-gtk/table.rb
113
128
  - lib/groonga/database-viewer-gtk/version.rb
114
129
  - lib/groonga/database-viewer-gtk/window.rb