vopwn55 / powerlang-issues

0 stars 0 forks source link

Adding Tabs (makes working with multiple scripts so much easier) #44

Open RRixxles opened 3 weeks ago

RRixxles commented 3 weeks ago

Adding tabs to the IDE would be so helpful.

I've made a fork with all of this including importing scripts from files now create a new tab with the correct name. Example of how it'd look: https://streamable.com/ldw5cv (copy and paste in ur URL bar)

IDEPlugin > Main (Paste this at line 274)

local LastClickTime = 0
local DoubleClickTime = 0.25

local function setupTab(tab)
    if tab:IsA("TextButton") then
        tab.Activated:Connect(function()
            local currentTab = MainWindow.Topbar.TabList.CurrentTab.Value
            if tab ~= currentTab then
                MainWindow.Topbar.TabList.CurrentTab.Value = tab
            end

            local CurrentClickTime = tick()  
            if (CurrentClickTime - LastClickTime) < DoubleClickTime then
                tab.ScriptInfo.ScriptName.Interactable = true
                tab.ScriptInfo.ScriptName:CaptureFocus()
                tab.ScriptInfo.ScriptName.SelectionStart = 1
            end

            LastClickTime = CurrentClickTime
        end)

        tab.ScriptInfo.ScriptName.FocusLost:Connect(function()
            tab.ScriptInfo.ScriptName.Interactable = false
            tab.ScriptInfo.ScriptName.SelectionStart = -1
        end)

        tab.CloseButton.Activated:Connect(function()
            local tabs = MainWindow.Topbar.TabList:GetChildren()
            local tabCount = 0

            for _, v in pairs(tabs) do
                if v:IsA("TextButton") then
                    tabCount = tabCount + 1
                end
            end

            if tabCount > 1 then
                local currentTab = MainWindow.Topbar.TabList.CurrentTab.Value
                if tab == currentTab then
                    MainWindow.Topbar.TabList.CurrentTab.Value = nil
                end
                tab:Destroy()
            end
        end)
    end
end

local function createTab(name, code)
    local newTab = MainWindow.Topbar.TabList.CurrentTab.Template:Clone()
    newTab.Name = "NewTab"

    if code ~= nil then
        newTab.Code.Value = code
    end

    newTab.ScriptInfo.ScriptName.Text = name
    newTab.Parent = MainWindow.Topbar.TabList

    MainWindow.Topbar.TabList.CurrentTab.Value = newTab
    return newTab
end

local firstTab = createTab("New Script", nil)
setupTab(firstTab)

MainWindow.Topbar.TabList.CurrentTab:GetPropertyChangedSignal("Value"):Connect(function()
    local currentTab = MainWindow.Topbar.TabList.CurrentTab.Value
    local tabs = MainWindow.Topbar.TabList:GetChildren()

    for _, v in pairs(tabs) do
        if v:IsA("TextButton") then
            local enabledBG = v:FindFirstChild("EnabledBG")
            enabledBG.Visible = false
        end
    end

    if currentTab then
        CodeBox.Text = currentTab.Code.Value
        local enabledBG = currentTab:FindFirstChild("EnabledBG")
        enabledBG.Visible = true
    else
        for _, v in pairs(tabs) do
            if v:IsA("TextButton") then
                MainWindow.Topbar.TabList.CurrentTab.Value = v
                CodeBox.Text = v.Code.Value
                local enabledBG = v:FindFirstChild("EnabledBG")
                enabledBG.Visible = true
                break
            end
        end
    end
end)

MainWindow.Topbar.TabList.NewTab.Activated:Connect(function()
    local tabCount = 0
    local tabs = MainWindow.Topbar.TabList:GetChildren()

    for _, v in pairs(tabs) do
        if v:IsA("TextButton") then
            tabCount = tabCount + 1
        end
    end

    if tabCount >= 20 then
        warn("Maximum amount of tabs! Please remove some before creating more.")
    else
        local newTab = createTab("New Script", nil)
        setupTab(newTab)
    end
end)

Replace the event fromdisk.activated in Main

MainWindow.Topbar.ToolSet.LoadOptions.FromDisk.Activated:Connect(function()
    HideSaveLoadOptions()
    local FileSelected:File = StudioService:PromptImportFile({"lua", "txt", "pw", "pwl"})
    if not FileSelected then
        -- User hasn't chosen anything
        return
    end
    FileOpenedName = FileSelected.Name

    local newTab = createTab(FileSelected.Name, FileSelected:GetBinaryContents())
    setupTab(newTab)

    MainWindow.Title = "PowerIDE - " .. FileSelected.Name
    MainWindow.Topbar.ToolSet.CurrentlyEditing.Text = "Editing: " .. FileSelected.Name
    DisplayRealContent()
end)

Replace the MainGUI screengui with the one in this fork:

https://discord.com/channels/645632117455323136/1296553324447010889/1302855339078848544 (copy and paste in ur URL bar)

vopwn55 commented 3 weeks ago

what is this barbaric solution