Files

54 lines
1.0 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Godot;
using System;
public partial class FileBar : TabBar
{
// Called when the node enters the scene tree for the first time.
public CodeEdit EditorWindow;
public override void _Ready()
{
TabClosePressed += OnTabClosePressed;
TabChanged += OnTabChanged;
TabClicked += OnTabChanged;
}
public void OpenFileAsTab(string path)
{
AddTab(path.GetFile());
int _ti = TabCount - 1;
var fa = FileAccess.Open(path, FileAccess.ModeFlags.Read);
if (fa != null)
{
SetTabMetadata(_ti, fa.GetAsText());
CurrentTab = _ti;
OnTabChanged(_ti);
}
}
private void OnTabClosePressed(long tabIndex)
{
RemoveTab((int)tabIndex);
if (tabIndex != 0)
{
CurrentTab = (int)tabIndex - 1;
OnTabChanged(tabIndex);
} else
{
EditorWindow.Text = "Create or open a file to use the editor! ";
}
}
private void OnTabChanged(long index)
{
var meta = GetTabMetadata((int)index);
if (meta.VariantType != Variant.Type.Nil)
{
EditorWindow.Text = meta.ToString();
}
}
}