Germinal 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/Germinal +3 -3
- data/lib/actions.rb +73 -0
- data/lib/application.rb +16 -43
- data/lib/color_selector.rb +9 -10
- data/lib/css_editor.rb +23 -23
- data/lib/font_selector.rb +6 -8
- data/lib/headerbar.rb +127 -0
- data/lib/notebook.rb +13 -18
- data/lib/resize_message.rb +2 -2
- data/lib/shortcuts.rb +76 -0
- data/lib/style_properties.rb +56 -0
- data/lib/terminal.rb +14 -22
- data/lib/terminal_chooser.rb +56 -61
- data/lib/window.rb +83 -189
- metadata +6 -3
- data/lib/terminal_overview.rb +0 -60
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright 2016 Cédric LE MOIGNE, cedlemo@gmx.com
|
2
|
+
# This file is part of Germinal.
|
3
|
+
#
|
4
|
+
# Germinal is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# any later version.
|
8
|
+
#
|
9
|
+
# Germinal is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with Germinal. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
module GerminalStyleProperties
|
18
|
+
def generate_string_rw_property(name, args)
|
19
|
+
GLib::Param::String.new(name.downcase,
|
20
|
+
name.capitalize,
|
21
|
+
name.upcase,
|
22
|
+
args,
|
23
|
+
GLib::Param::READABLE |
|
24
|
+
GLib::Param::WRITABLE)
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_int_rw_property(name, args)
|
28
|
+
GLib::Param::Int.new(name.downcase,
|
29
|
+
name.capitalize,
|
30
|
+
name.upcase,
|
31
|
+
*args,
|
32
|
+
GLib::Param::READABLE |
|
33
|
+
GLib::Param::WRITABLE)
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_boxed_rw_property(name, args)
|
37
|
+
GLib::Param::Boxed.new(name.downcase,
|
38
|
+
name.capitalize,
|
39
|
+
name.upcase,
|
40
|
+
args,
|
41
|
+
GLib::Param::READABLE |
|
42
|
+
GLib::Param::WRITABLE)
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_rw_property(type, name, args)
|
46
|
+
type = type.to_s.downcase
|
47
|
+
method_name = "generate_#{type}_rw_property"
|
48
|
+
return false unless methods.include?(method_name.to_sym)
|
49
|
+
method(method_name.to_sym).call(name, args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def install_style(type, name, args)
|
53
|
+
property = generate_rw_property(type, name, args)
|
54
|
+
install_style_property(property) if property
|
55
|
+
end
|
56
|
+
end
|
data/lib/terminal.rb
CHANGED
@@ -18,32 +18,24 @@ TERMINAL_COLOR_NAMES = [:foreground, :background, :black, :red, :green, :yellow,
|
|
18
18
|
:brightblack, :brightred, :brightgreen, :brightyellow, :brightblue, :brightmagenta, :brightcyan, :brightwhite]
|
19
19
|
DEFAULT_TERMINAL_COLORS = %w(#aeafad #323232 #000000 #b9214f #A6E22E #ff9800 #3399ff #8e33ff #06a2dc
|
20
20
|
#B0B0B0 #5D5D5D #ff5c8d #CDEE69 #ffff00 #9CD9F0 #FBB1F9 #77DFD8 #F7F7F7)
|
21
|
-
DEFAULT_TERMINAL_FONT = "Monospace 11"
|
21
|
+
DEFAULT_TERMINAL_FONT = "Monospace 11"
|
22
22
|
##
|
23
23
|
# The default vte terminal customized
|
24
24
|
class GerminalTerminal < Vte::Terminal
|
25
|
+
extend GerminalStyleProperties
|
25
26
|
attr_reader :pid, :menu
|
26
27
|
attr_accessor :preview, :colors, :tab_label
|
27
28
|
type_register
|
28
|
-
TERMINAL_COLOR_NAMES.each_with_index do |c
|
29
|
+
TERMINAL_COLOR_NAMES.each_with_index do |c|
|
29
30
|
name = c.to_s
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
name.upcase, # blurb
|
34
|
-
GLib::Type["GdkRGBA"],
|
35
|
-
GLib::Param::READABLE |
|
36
|
-
GLib::Param::WRITABLE)
|
37
|
-
)
|
31
|
+
self.install_style("boxed",
|
32
|
+
name,
|
33
|
+
GLib::Type["GdkRGBA"])
|
38
34
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
GLib::Type["PangoFontDescription"],
|
44
|
-
GLib::Param::READABLE |
|
45
|
-
GLib::Param::WRITABLE)
|
46
|
-
)
|
35
|
+
self.install_style("boxed",
|
36
|
+
"font",
|
37
|
+
GLib::Type["PangoFontDescription"])
|
38
|
+
|
47
39
|
##
|
48
40
|
# Create a new GerminalTerminal instance that runs command_string
|
49
41
|
def initialize(command_string, working_dir = nil)
|
@@ -80,7 +72,7 @@ class GerminalTerminal < Vte::Terminal
|
|
80
72
|
|
81
73
|
builder = Gtk::Builder.new(:resource => "/com/github/cedlemo/germinal/terminal-menu.ui")
|
82
74
|
@menu = Gtk::Popover.new(self, builder["termmenu"])
|
83
|
-
|
75
|
+
|
84
76
|
signal_connect "button-press-event" do |widget, event|
|
85
77
|
if event.type == Gdk::EventType::BUTTON_PRESS &&
|
86
78
|
event.button == Gdk::BUTTON_SECONDARY
|
@@ -101,7 +93,7 @@ class GerminalTerminal < Vte::Terminal
|
|
101
93
|
configure
|
102
94
|
end
|
103
95
|
|
104
|
-
def
|
96
|
+
def pid_dir
|
105
97
|
File.readlink("/proc/#{@pid}/cwd")
|
106
98
|
end
|
107
99
|
|
@@ -117,7 +109,7 @@ class GerminalTerminal < Vte::Terminal
|
|
117
109
|
end
|
118
110
|
[background, foreground] + colors
|
119
111
|
end
|
120
|
-
|
112
|
+
|
121
113
|
def get_css_font
|
122
114
|
font = style_get_property("font")
|
123
115
|
unless font
|
@@ -125,7 +117,7 @@ class GerminalTerminal < Vte::Terminal
|
|
125
117
|
end
|
126
118
|
font
|
127
119
|
end
|
128
|
-
|
120
|
+
|
129
121
|
def apply_colors
|
130
122
|
set_colors(@colors[0], @colors[1], @colors[2..-1])
|
131
123
|
end
|
data/lib/terminal_chooser.rb
CHANGED
@@ -17,11 +17,11 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
17
17
|
def initialize(window)
|
18
18
|
super(nil, nil)
|
19
19
|
@window = window
|
20
|
-
set_size_request(
|
20
|
+
set_size_request(184, @window.notebook.current.allocation.to_a[3] - 8)
|
21
21
|
set_halign(:end)
|
22
22
|
set_valign(:center)
|
23
23
|
set_name("terminal_chooser")
|
24
|
-
|
24
|
+
|
25
25
|
generate_previews_pixbufs
|
26
26
|
generate_grid
|
27
27
|
fill_grid
|
@@ -32,6 +32,7 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
|
+
|
35
36
|
def generate_grid
|
36
37
|
@grid = Gtk::Grid.new
|
37
38
|
@grid.valign = :start
|
@@ -40,18 +41,18 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def fill_grid
|
43
|
-
@window.notebook.children.each_with_index do |child,i|
|
44
|
-
button = generate_preview_button(child, i)
|
45
|
-
@grid.attach(button, 0
|
44
|
+
@window.notebook.children.each_with_index do |child, i|
|
45
|
+
button = generate_preview_button(child, i)
|
46
|
+
@grid.attach(button, 0, i, 1, 1)
|
46
47
|
add_drag_and_drop_functionalities(button)
|
47
48
|
button = generate_close_tab_button
|
48
|
-
@grid.attach(button, 1
|
49
|
+
@grid.attach(button, 1, i, 1, 1)
|
49
50
|
end
|
50
51
|
@grid.attach(generate_separator, 0, @window.notebook.n_pages, 2, 1)
|
51
52
|
button = generate_quit_button
|
52
53
|
@grid.attach(button, 0, @window.notebook.n_pages + 1, 2, 1)
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
def generate_close_tab_button
|
56
57
|
button = Gtk::EventBox.new
|
57
58
|
button.tooltip_text = "Close Tab"
|
@@ -65,33 +66,33 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
65
66
|
n = @grid.child_get_property(button, "top-attach")
|
66
67
|
tab = @window.notebook.get_nth_page(n)
|
67
68
|
if @window.notebook.n_pages == 1
|
68
|
-
@window.quit_gracefully
|
69
|
+
@window.quit_gracefully
|
69
70
|
else
|
70
71
|
remove_tab(tab, n)
|
71
72
|
end
|
72
73
|
end
|
73
|
-
button
|
74
|
+
button
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
def remove_tab(tab, n)
|
77
78
|
@window.notebook.remove(tab)
|
78
79
|
@grid.remove_row(n)
|
79
80
|
last_tab = @window.notebook.n_pages - 1
|
80
81
|
update_preview_button_tooltip(n..last_tab)
|
81
82
|
end
|
82
|
-
|
83
|
+
|
83
84
|
def update_preview_button_tooltip(range)
|
84
85
|
(range).each do |j|
|
85
86
|
puts j
|
86
87
|
@grid.get_child_at(0, j).tooltip_text = j.to_s
|
87
88
|
end
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
def generate_preview_button(child, i)
|
91
92
|
button = Gtk::Button.new
|
92
93
|
button.add(generate_preview_image(child.preview))
|
93
94
|
button.set_tooltip_text(i.to_s)
|
94
|
-
button.signal_connect "clicked" do
|
95
|
+
button.signal_connect "clicked" do
|
95
96
|
@window.notebook.gen_preview = false
|
96
97
|
@window.notebook.set_current_page(i)
|
97
98
|
end
|
@@ -99,7 +100,6 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def generate_preview_image(pixbuf)
|
102
|
-
ratio = pixbuf.width / pixbuf.height
|
103
103
|
scaled_pix = pixbuf.scale(150, 75, Gdk::Pixbuf::INTERP_BILINEAR)
|
104
104
|
img = Gtk::Image.new(:pixbuf => scaled_pix)
|
105
105
|
img.show
|
@@ -120,24 +120,24 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
120
120
|
end
|
121
121
|
button
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def generate_previews_pixbufs
|
125
125
|
current_page = @window.notebook.page
|
126
|
-
|
126
|
+
|
127
127
|
if @window.notebook.children.size == 1
|
128
|
-
|
129
|
-
_x,_y,w,h = @window.notebook.current.allocation.to_a
|
130
|
-
@window.notebook.current.preview = @window.notebook.current.window.to_pixbuf(0, 0, w, h)
|
128
|
+
# If we have only one vte, just generate the preview
|
129
|
+
_x, _y, w, h = @window.notebook.current.allocation.to_a
|
130
|
+
@window.notebook.current.preview = @window.notebook.current.window.to_pixbuf(0, 0, w, h)
|
131
131
|
else
|
132
|
-
|
133
|
-
|
132
|
+
# If we have more terminals, just cycle through them
|
133
|
+
# the previews will be generated in the "switch-page" event of the notebook
|
134
134
|
begin
|
135
135
|
@window.notebook.cycle_next_page
|
136
136
|
end while @window.notebook.page == current_page
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
# Here I disable the preview generation in the notebook "switch-page" event
|
138
|
+
# before returning to the current page.
|
139
|
+
# This is a Hack, If I don't disable the preview, all the previews will be
|
140
|
+
# the same.
|
141
141
|
@window.notebook.gen_preview = false
|
142
142
|
@window.notebook.set_current_page(current_page)
|
143
143
|
end
|
@@ -147,50 +147,49 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
147
147
|
add_dnd_source(button)
|
148
148
|
add_dnd_destination(button)
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
def add_dnd_source(button)
|
152
152
|
button.drag_source_set(Gdk::ModifierType::BUTTON1_MASK |
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
153
|
+
Gdk::ModifierType::BUTTON2_MASK,
|
154
|
+
[["test", Gtk::TargetFlags::SAME_APP, 12_345]],
|
155
|
+
Gdk::DragAction::COPY |
|
156
|
+
Gdk::DragAction::MOVE)
|
157
157
|
button.drag_source_set_icon_name("grab")
|
158
158
|
# Drag source signals
|
159
159
|
# drag-begin User starts a drag Set-up drag icon
|
160
160
|
# drag-data-get When drag data is requested by the destination Transfer drag data from source to destination
|
161
|
-
# drag-data-delete When a drag with the action Gdk.DragAction.MOVE is completed Delete data from the source to complete the
|
161
|
+
# drag-data-delete When a drag with the action Gdk.DragAction.MOVE is completed Delete data from the source to complete the "move"
|
162
162
|
# drag-end When the drag is complete Undo anything done in drag-begin
|
163
|
-
|
164
|
-
#button.signal_connect "drag-begin" do
|
165
|
-
#
|
166
|
-
#end
|
163
|
+
|
164
|
+
# button.signal_connect "drag-begin" do
|
165
|
+
# puts "drag begin for #{index}"
|
166
|
+
# end
|
167
167
|
button.signal_connect("drag-data-get") do |_widget, _context, selection_data, _info, _time|
|
168
|
-
|
169
168
|
index = @grid.child_get_property(button, "top-attach")
|
170
169
|
selection_data.set(Gdk::Selection::TYPE_INTEGER, index.to_s)
|
171
170
|
end
|
172
|
-
#button.signal_connect "drag-data-delete" do
|
173
|
-
#
|
174
|
-
#end
|
175
|
-
#button.signal_connect "drag-end" do
|
176
|
-
#
|
177
|
-
#end
|
171
|
+
# button.signal_connect "drag-data-delete" do
|
172
|
+
# puts "drag data delete for #{inex}"
|
173
|
+
# end
|
174
|
+
# button.signal_connect "drag-end" do
|
175
|
+
# puts "drag end for #{index}"
|
176
|
+
# end
|
178
177
|
end
|
179
|
-
|
178
|
+
|
180
179
|
def add_dnd_destination(button)
|
181
180
|
button.drag_dest_set(Gtk::DestDefaults::MOTION |
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
Gtk::DestDefaults::HIGHLIGHT,
|
182
|
+
[["test", :same_app, 12_345]],
|
183
|
+
Gdk::DragAction::COPY |
|
184
|
+
Gdk::DragAction::MOVE)
|
185
|
+
|
187
186
|
# Drag destination signals
|
188
187
|
# drag-motion Drag icon moves over a drop area Allow only certain areas to be dropped onto
|
189
188
|
# drag-drop Icon is dropped onto a drag area Allow only certain areas to be dropped onto
|
190
|
-
# drag-data-received When drag data is received by the destination Transfer drag data from source to destination
|
191
|
-
#button.signal_connect "drag-motion" do
|
192
|
-
#
|
193
|
-
#end
|
189
|
+
# drag-data-received When drag data is received by the destination Transfer drag data from source to destination
|
190
|
+
# button.signal_connect "drag-motion" do
|
191
|
+
# puts "drag motion for #{index}"
|
192
|
+
# end
|
194
193
|
button.signal_connect("drag-drop") do |widget, context, _x, _y, time|
|
195
194
|
widget.drag_get_data(context, context.targets[0], time)
|
196
195
|
end
|
@@ -198,17 +197,13 @@ class GerminalTermChooser < Gtk::ScrolledWindow
|
|
198
197
|
index = @grid.child_get_property(button, "top-attach")
|
199
198
|
index_of_dragged_object = index
|
200
199
|
context.targets.each do |target|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
index_of_dragged_object = selection_data.data[0].pack("C#{data_len}").to_i
|
205
|
-
else
|
206
|
-
next
|
207
|
-
end
|
200
|
+
next unless target.name == "test" || selection_data.type == :type_integer
|
201
|
+
data_len = selection_data.data[1]
|
202
|
+
index_of_dragged_object = selection_data.data[0].pack("C#{data_len}").to_i
|
208
203
|
end
|
209
204
|
if index_of_dragged_object != index
|
210
|
-
|
211
|
-
@window.notebook.reorder_child(
|
205
|
+
dragged = @window.notebook.get_nth_page(index_of_dragged_object)
|
206
|
+
@window.notebook.reorder_child(dragged, index)
|
212
207
|
@window.notebook.children.each_with_index do |child, i|
|
213
208
|
@grid.get_child_at(0, i).image = generate_preview_image(child.preview)
|
214
209
|
end
|