mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +01:00
Allow to inspect index and commit files
This commit is contained in:
parent
0780ebc692
commit
0670a8ebdf
8 changed files with 152 additions and 39 deletions
|
@ -6,16 +6,28 @@ enum FileBrowserMode {
|
|||
INDEX
|
||||
}
|
||||
|
||||
export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY
|
||||
export(String) var title setget _set_title
|
||||
export(FileBrowserMode) var mode = FileBrowserMode.WORKING_DIRECTORY setget _set_mode
|
||||
|
||||
var shell
|
||||
var commit setget _set_commit
|
||||
var repository
|
||||
|
||||
var open_file
|
||||
|
||||
onready var grid = $Panel/Margin/Rows/Scroll/Grid
|
||||
onready var text_edit = $Panel/TextEdit
|
||||
onready var save_button = $Panel/TextEdit/SaveButton
|
||||
onready var title_label = $Panel/Margin/Rows/Title
|
||||
|
||||
func _ready():
|
||||
update()
|
||||
_set_mode(mode)
|
||||
_set_title(title)
|
||||
|
||||
func _input(event):
|
||||
if event.is_action_pressed("save"):
|
||||
save()
|
||||
|
||||
func clear():
|
||||
for item in grid.get_children():
|
||||
|
@ -49,7 +61,7 @@ func update():
|
|||
for file_path in files:
|
||||
var item = preload("res://file_browser_item.tscn").instance()
|
||||
item.label = file_path
|
||||
#item.connect("clicked", self, "item_clicked")
|
||||
item.connect("clicked", self, "item_clicked")
|
||||
grid.add_child(item)
|
||||
FileBrowserMode.INDEX:
|
||||
if repository:
|
||||
|
@ -59,17 +71,57 @@ func update():
|
|||
for file_path in files:
|
||||
var item = preload("res://file_browser_item.tscn").instance()
|
||||
item.label = file_path
|
||||
#item.connect("clicked", self, "item_clicked")
|
||||
item.connect("clicked", self, "item_clicked")
|
||||
grid.add_child(item)
|
||||
|
||||
func item_clicked(item):
|
||||
var file_path = item.label
|
||||
shell.run("'%s'/fake-editor-noblock '%s'" % [game.tmp_prefix_inside, file_path])
|
||||
print(item.label)
|
||||
open_file = item.label
|
||||
match mode:
|
||||
FileBrowserMode.WORKING_DIRECTORY:
|
||||
text_edit.text = helpers.read_file(shell._cwd + item.label)
|
||||
FileBrowserMode.COMMIT:
|
||||
text_edit.text = commit.repository.shell.run("git show %s:\"%s\"" % [commit.id, item.label])
|
||||
FileBrowserMode.INDEX:
|
||||
text_edit.text = repository.shell.run("git show :\"%s\"" % [item.label])
|
||||
text_edit.show()
|
||||
text_edit.grab_focus()
|
||||
|
||||
func close():
|
||||
text_edit.hide()
|
||||
|
||||
func save():
|
||||
match mode:
|
||||
FileBrowserMode.WORKING_DIRECTORY:
|
||||
var fixme_path = shell._cwd
|
||||
|
||||
# Add a newline to the end of the file if there is none.
|
||||
if text_edit.text.length() > 0 and text_edit.text.substr(text_edit.text.length()-1, 1) != "\n":
|
||||
text_edit.text += "\n"
|
||||
|
||||
helpers.write_file(fixme_path+open_file, text_edit.text)
|
||||
close()
|
||||
|
||||
func _set_commit(new_commit):
|
||||
commit = new_commit
|
||||
update()
|
||||
|
||||
func _set_mode(new_mode):
|
||||
mode = new_mode
|
||||
if save_button:
|
||||
save_button.visible = mode == FileBrowserMode.WORKING_DIRECTORY
|
||||
text_edit.readonly = not mode == FileBrowserMode.WORKING_DIRECTORY
|
||||
text_edit.selecting_enabled = mode == FileBrowserMode.WORKING_DIRECTORY
|
||||
if mode == FileBrowserMode.WORKING_DIRECTORY:
|
||||
text_edit.focus_mode = Control.FOCUS_CLICK
|
||||
else:
|
||||
text_edit.focus_mode = Control.FOCUS_NONE
|
||||
|
||||
func _set_title(new_title):
|
||||
title = new_title
|
||||
if title_label:
|
||||
title_label.text = new_title
|
||||
|
||||
func very_best_sort(a,b):
|
||||
# We're looking at the third character because all entries have the form
|
||||
# "./.git/bla".
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://file_browser.gd" type="Script" id=1]
|
||||
[ext_resource path="res://fonts/default.tres" type="DynamicFont" id=2]
|
||||
[ext_resource path="res://styles/theme.tres" type="Theme" id=3]
|
||||
|
||||
[node name="FileBrowser" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
rect_min_size = Vector2( 0, 142 )
|
||||
theme = ExtResource( 3 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
|
@ -35,11 +37,17 @@ margin_left = 8.0
|
|||
margin_top = 8.0
|
||||
margin_right = 1912.0
|
||||
margin_bottom = 1072.0
|
||||
custom_constants/separation = 32
|
||||
custom_constants/separation = 0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Title" type="Label" parent="Panel/Margin/Rows"]
|
||||
margin_right = 1904.0
|
||||
margin_bottom = 25.0
|
||||
text = "title"
|
||||
align = 1
|
||||
|
||||
[node name="Breadcrumbs" type="HBoxContainer" parent="Panel/Margin/Rows"]
|
||||
visible = false
|
||||
margin_right = 1856.0
|
||||
|
@ -59,6 +67,7 @@ margin_bottom = 50.0
|
|||
text = "dir"
|
||||
|
||||
[node name="Scroll" type="ScrollContainer" parent="Panel/Margin/Rows"]
|
||||
margin_top = 25.0
|
||||
margin_right = 1904.0
|
||||
margin_bottom = 1064.0
|
||||
size_flags_horizontal = 3
|
||||
|
@ -66,7 +75,7 @@ size_flags_vertical = 3
|
|||
|
||||
[node name="Grid" type="GridContainer" parent="Panel/Margin/Rows/Scroll"]
|
||||
margin_right = 1904.0
|
||||
margin_bottom = 1064.0
|
||||
margin_bottom = 1039.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
custom_constants/vseparation = 16
|
||||
|
@ -75,3 +84,45 @@ columns = 4
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="TextEdit" type="TextEdit" parent="Panel"]
|
||||
visible = false
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="SaveButton" type="Button" parent="Panel/TextEdit"]
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -114.396
|
||||
margin_top = -59.399
|
||||
margin_right = -14.3955
|
||||
margin_bottom = -14.399
|
||||
focus_mode = 0
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
enabled_focus_mode = 0
|
||||
text = "Save"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CloseButton" type="Button" parent="Panel/TextEdit"]
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
margin_left = -54.3247
|
||||
margin_top = 12.0
|
||||
margin_right = -14.3247
|
||||
margin_bottom = 52.0
|
||||
focus_mode = 0
|
||||
custom_fonts/font = ExtResource( 2 )
|
||||
enabled_focus_mode = 0
|
||||
text = "x"
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
[connection signal="pressed" from="Panel/TextEdit/SaveButton" to="." method="save"]
|
||||
[connection signal="pressed" from="Panel/TextEdit/CloseButton" to="." method="close"]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
title = Reodering events
|
||||
title = Reordering events
|
||||
|
||||
[description]
|
||||
|
||||
|
|
2
node.gd
2
node.gd
|
@ -55,6 +55,7 @@ func type_set(new_type):
|
|||
type = new_type
|
||||
if type == "commit":
|
||||
$FileBrowser.commit = self
|
||||
$FileBrowser.title = "Commit"
|
||||
if type != "ref":
|
||||
$ID.text = $ID.text.substr(0,8)
|
||||
#elif type == "ref":
|
||||
|
@ -113,6 +114,7 @@ func _input(event):
|
|||
if hovered:
|
||||
if event.is_action_pressed("click"):
|
||||
held = true
|
||||
if type == "commit":
|
||||
$FileBrowser.visible = not $FileBrowser.visible
|
||||
elif event.is_action_pressed("right_click"):
|
||||
var input = get_tree().get_current_scene().find_node("Input")
|
||||
|
|
|
@ -85,10 +85,11 @@ __meta__ = {
|
|||
visible = false
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 32.0
|
||||
margin_top = -25.0
|
||||
margin_right = 460.0
|
||||
margin_bottom = 93.0
|
||||
margin_left = -460.672
|
||||
margin_top = -23.6409
|
||||
margin_right = -32.6716
|
||||
margin_bottom = 94.3591
|
||||
mouse_filter = 1
|
||||
mode = 1
|
||||
[connection signal="mouse_entered" from="Rect" to="." method="_on_hover"]
|
||||
[connection signal="mouse_exited" from="Rect" to="." method="_on_unhover"]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
extends Control
|
||||
|
||||
onready var index = $Rows/RepoVis/Index
|
||||
onready var index = $Rows/Browsers/Index
|
||||
onready var nodes = $Rows/RepoVis/Nodes
|
||||
onready var file_browser = $Rows/FileBrowser
|
||||
onready var file_browser = $Rows/Browsers/FileBrowser
|
||||
onready var label_node = $Rows/RepoVis/Label
|
||||
onready var path_node = $Rows/RepoVis/Path
|
||||
onready var simplify_checkbox = $Rows/RepoVis/SimplifyCheckbox
|
||||
|
|
|
@ -25,7 +25,7 @@ __meta__ = {
|
|||
|
||||
[node name="RepoVis" type="Control" parent="Rows"]
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 901.0
|
||||
margin_bottom = 926.0
|
||||
mouse_filter = 2
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
|
@ -43,14 +43,6 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Index" parent="Rows/RepoVis" instance=ExtResource( 4 )]
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 22.0
|
||||
margin_top = 65.0
|
||||
margin_right = -17.0
|
||||
margin_bottom = 188.0
|
||||
mode = 2
|
||||
|
||||
[node name="IndexLabel" type="Label" parent="Rows/RepoVis"]
|
||||
visible = false
|
||||
margin_left = 21.0
|
||||
|
@ -106,14 +98,28 @@ __meta__ = {
|
|||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="FileBrowser" parent="Rows" instance=ExtResource( 4 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_top = 913.0
|
||||
[node name="Browsers" type="VBoxContainer" parent="Rows"]
|
||||
margin_top = 938.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1080.0
|
||||
|
||||
[node name="Index" parent="Rows/Browsers" instance=ExtResource( 4 )]
|
||||
visible = false
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 142.0
|
||||
size_flags_vertical = 3
|
||||
size_flags_stretch_ratio = 0.19
|
||||
title = "Index"
|
||||
mode = 2
|
||||
|
||||
[node name="FileBrowser" parent="Rows/Browsers" instance=ExtResource( 4 )]
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 142.0
|
||||
size_flags_vertical = 3
|
||||
title = "Working directory"
|
||||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
|
||||
[connection signal="pressed" from="Rows/RepoVis/Button" to="." method="update_everything"]
|
||||
|
|
|
@ -35,6 +35,7 @@ func open(filename):
|
|||
grab_focus()
|
||||
|
||||
func save():
|
||||
if visible:
|
||||
var fixme_path = game.tmp_prefix_outside+"repos/"
|
||||
|
||||
# Add a newline to the end of the file if there is none.
|
||||
|
|
Loading…
Reference in a new issue