mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-23 03:05:32 +02:00
Godot 4 automatic changes
This commit is contained in:
parent
8b5caafbc7
commit
cdbf3f2adc
75 changed files with 1034 additions and 952 deletions
|
@ -4,7 +4,7 @@
|
|||
# These snippets are copyright of their authors and released under the MIT license:
|
||||
# - Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur (MIT License).
|
||||
# - Copyright (c) 2014-2021 Godot Engine contributors (MIT License).
|
||||
tool
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
const EditorTerminal := preload("./editor_terminal.tscn")
|
||||
|
@ -23,23 +23,23 @@ enum TerminalPopupMenuOptions {
|
|||
}
|
||||
|
||||
# Has access to the EditorSettings singleton so it can dynamically generate the
|
||||
# terminal color scheme based on editor theme settings.
|
||||
# terminal color scheme based checked editor theme settings.
|
||||
var editor_plugin: EditorPlugin
|
||||
var editor_interface: EditorInterface
|
||||
|
||||
onready var editor_settings: EditorSettings = editor_interface.get_editor_settings()
|
||||
onready var tabs: Tabs = $VBoxContainer/TabbarContainer/Tabs
|
||||
onready var tabbar_container: HBoxContainer = $VBoxContainer/TabbarContainer
|
||||
onready var add_button: ToolButton = $VBoxContainer/TabbarContainer/Tabs/AddButton
|
||||
onready var tab_container: TabContainer = $VBoxContainer/TabContainer
|
||||
onready var terminal_popup_menu: PopupMenu = $VBoxContainer/TerminalPopupMenu
|
||||
@onready var editor_settings: EditorSettings = editor_interface.get_editor_settings()
|
||||
@onready var tabs: TabBar = $VBoxContainer/TabbarContainer/TabBar
|
||||
@onready var tabbar_container: HBoxContainer = $VBoxContainer/TabbarContainer
|
||||
@onready var add_button: Button = $VBoxContainer/TabbarContainer/TabBar/AddButton
|
||||
@onready var tab_container: TabContainer = $VBoxContainer/TabContainer
|
||||
@onready var terminal_popup_menu: PopupMenu = $VBoxContainer/TerminalPopupMenu
|
||||
|
||||
# Size label.
|
||||
# Used to show the size of the terminal (rows/cols) and panel (pixels) when resized.
|
||||
onready var size_label: Label = $SizeLabel
|
||||
onready var size_label_timer: Timer = $SizeLabel/SizeLabelTimer
|
||||
@onready var size_label: Label = $SizeLabel
|
||||
@onready var size_label_timer: Timer = $SizeLabel/SizeLabelTimer
|
||||
|
||||
onready var ready := true
|
||||
@onready var ready := true
|
||||
|
||||
var _theme := Theme.new()
|
||||
var _settings: TerminalSettings
|
||||
|
@ -47,7 +47,7 @@ var _tab_container_min_size
|
|||
|
||||
|
||||
func _ready():
|
||||
tab_container.add_stylebox_override("panel", get_stylebox("background", "EditorStyles"))
|
||||
tab_container.add_theme_stylebox_override("panel", get_stylebox("background", "EditorStyles"))
|
||||
_update_settings()
|
||||
|
||||
|
||||
|
@ -76,10 +76,10 @@ func _update_settings() -> void:
|
|||
if editor_interface.has_method("get_editor_scale"):
|
||||
editor_scale = editor_interface.get_editor_scale()
|
||||
|
||||
rect_min_size = Vector2(0, tabbar_container.rect_size.y + 182) * editor_scale
|
||||
rect_size.y = 415
|
||||
minimum_size = Vector2(0, tabbar_container.size.y + 182) * editor_scale
|
||||
size.y = 415
|
||||
|
||||
tabs.tab_close_display_policy = Tabs.CLOSE_BUTTON_SHOW_ALWAYS
|
||||
tabs.tab_close_display_policy = TabBar.CLOSE_BUTTON_SHOW_ALWAYS
|
||||
|
||||
# Update shortcuts.
|
||||
if _settings.new_terminal_shortcut:
|
||||
|
@ -104,13 +104,13 @@ func _update_settings() -> void:
|
|||
|
||||
func _update_terminal_tabs():
|
||||
# Wait a couple of frames to allow everything to resize before updating.
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), "idle_frame")
|
||||
await get_tree().idle_frame
|
||||
await get_tree().idle_frame
|
||||
|
||||
if tabs.get_offset_buttons_visible():
|
||||
# Move add button to fixed position on the tabbar.
|
||||
# Move add button to fixed position checked the tabbar.
|
||||
if add_button.get_parent() == tabs:
|
||||
add_button.rect_position = Vector2.ZERO
|
||||
add_button.position = Vector2.ZERO
|
||||
tabs.remove_child(add_button)
|
||||
tabbar_container.add_child(add_button)
|
||||
tabbar_container.move_child(add_button, 0)
|
||||
|
@ -122,7 +122,7 @@ func _update_terminal_tabs():
|
|||
var last_tab := Rect2()
|
||||
if tabs.get_tab_count() > 0:
|
||||
last_tab = tabs.get_tab_rect(tabs.get_tab_count() - 1)
|
||||
add_button.rect_position = Vector2(
|
||||
add_button.position = Vector2(
|
||||
last_tab.position.x + last_tab.size.x + 3, last_tab.position.y
|
||||
)
|
||||
|
||||
|
@ -132,12 +132,12 @@ func _update_terminal_tabs():
|
|||
|
||||
func _on_AddButton_pressed():
|
||||
var shell = OS.get_environment("SHELL") if OS.has_environment("SHELL") else "sh"
|
||||
var terminal := EditorTerminal.instance()
|
||||
var terminal := EditorTerminal.instantiate()
|
||||
tabs.add_tab(shell.get_file())
|
||||
terminal.editor_settings = editor_settings
|
||||
terminal.set_anchors_preset(PRESET_WIDE)
|
||||
terminal.connect("gui_input", self, "_on_TabContainer_gui_input")
|
||||
terminal.connect("exited", self, "_on_Terminal_exited", [terminal])
|
||||
terminal.connect("gui_input",Callable(self,"_on_TabContainer_gui_input"))
|
||||
terminal.connect("exited",Callable(self,"_on_Terminal_exited").bind(terminal))
|
||||
tab_container.add_child(terminal)
|
||||
terminal.pty.fork(shell)
|
||||
terminal.grab_focus()
|
||||
|
@ -172,7 +172,7 @@ func _notification(what):
|
|||
_update_terminal_tabs()
|
||||
NOTIFICATION_RESIZED:
|
||||
_update_terminal_tabs()
|
||||
NOTIFICATION_WM_FOCUS_IN:
|
||||
NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
_update_terminal_tabs()
|
||||
|
||||
|
||||
|
@ -182,7 +182,7 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
# Global shortcut to open new terminal and make terminal panel visible.
|
||||
if _settings.new_terminal_shortcut and _settings.new_terminal_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.new_terminal_shortcut.shortcut):
|
||||
if event.is_match(_settings.new_terminal_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
editor_plugin.make_bottom_panel_item_visible(self)
|
||||
_on_AddButton_pressed()
|
||||
|
@ -194,38 +194,38 @@ func _input(event: InputEvent) -> void:
|
|||
):
|
||||
# Kill terminal.
|
||||
if _settings.kill_terminal_shortcut and _settings.kill_terminal_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.kill_terminal_shortcut.shortcut):
|
||||
if event.is_match(_settings.kill_terminal_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
_on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.KILL_TERMINAL)
|
||||
|
||||
# Copy.
|
||||
if _settings.copy_shortcut and _settings.copy_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.copy_shortcut.shortcut):
|
||||
if event.is_match(_settings.copy_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
_on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.COPY)
|
||||
|
||||
# Paste.
|
||||
if _settings.paste_shortcut and _settings.paste_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.paste_shortcut.shortcut):
|
||||
if event.is_match(_settings.paste_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
_on_TerminalPopupMenu_id_pressed(TerminalPopupMenuOptions.PASTE)
|
||||
|
||||
# Next tab.
|
||||
if _settings.next_tab_shortcut and _settings.next_tab_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.next_tab_shortcut.shortcut):
|
||||
if event.is_match(_settings.next_tab_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
tabs.current_tab = min(tabs.current_tab + 1, tabs.get_tab_count() - 1)
|
||||
|
||||
# Previous tab.
|
||||
if _settings.previous_tab_shortcut and _settings.previous_tab_shortcut.shortcut:
|
||||
if event.shortcut_match(_settings.previous_tab_shortcut.shortcut):
|
||||
if event.is_match(_settings.previous_tab_shortcut.shortcut):
|
||||
get_tree().set_input_as_handled()
|
||||
tabs.current_tab = max(tabs.current_tab - 1, 0)
|
||||
|
||||
|
||||
func _on_TabContainer_gui_input(event):
|
||||
if event is InputEventMouseButton and event.button_index == BUTTON_RIGHT:
|
||||
terminal_popup_menu.rect_position = event.global_position
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
terminal_popup_menu.position = event.global_position
|
||||
terminal_popup_menu.popup()
|
||||
|
||||
|
||||
|
@ -243,7 +243,7 @@ func _on_TerminalPopupMenu_id_pressed(id):
|
|||
for i in OS.clipboard.length():
|
||||
var event = InputEventKey.new()
|
||||
event.unicode = ord(OS.clipboard[i])
|
||||
event.pressed = true
|
||||
event.button_pressed = true
|
||||
terminal._gui_input(event)
|
||||
TerminalPopupMenuOptions.COPY_ALL:
|
||||
OS.clipboard = terminal.copy_all()
|
||||
|
@ -262,7 +262,7 @@ func _on_Panel_resized():
|
|||
if not size_label:
|
||||
return
|
||||
|
||||
var size = tab_container.rect_size
|
||||
var size = tab_container.size
|
||||
if tabs.get_tab_count() > 0:
|
||||
var terminal = tab_container.get_child(tabs.current_tab)
|
||||
var cols = terminal.get_cols()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue