initial commit
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
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());
|
||||
GD.Print(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user