Skip to content

Commit

Permalink
Fixup tab closing (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jan 28, 2024
1 parent 44aee66 commit 8516ab2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/SerialLoops/Controls/EditorTabsPanel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using Eto.Forms;
using Eto.Forms;
using HaruhiChokuretsuLib.Util;
using SerialLoops.Editors;
using SerialLoops.Lib;
using SerialLoops.Lib.Items;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SerialLoops.Controls
Expand Down Expand Up @@ -114,7 +114,7 @@ private DocumentPage CreateTab(ItemDescription item, Project project, ILogger lo
}
}

private void Tabs_PageClosed(object sender, DocumentPageEventArgs e)
public void Tabs_PageClosed(object sender, DocumentPageEventArgs e)
{
if (e.Page.GetType() == typeof(BackgroundMusicEditor))
{
Expand All @@ -141,7 +141,10 @@ public void Tabs_PageChanged(object sender, EventArgs e)

// Add editor-specific toolbar commands
List<Command> commands = ((Editor)Tabs.SelectedPage)?.EditorCommands;
if (commands is null || commands.Count == 0) return;
if (commands is null || commands.Count == 0)
{
return;
}

SubMenuItem editItem = new() { Text = "&Edit", Tag = Editor.EDITOR_TOOLBAR_TAG };
SeparatorToolItem separator = new() { Tag = Editor.EDITOR_TOOLBAR_TAG, Style = "sl-toolbar-separator" };
Expand Down
19 changes: 16 additions & 3 deletions src/SerialLoops/Controls/TabContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public TabContextMenu(EditorTabsPanel tabs, ILogger log) : base()
Opening += ContextMenu_OnOpen;

Command closeTabCommand = new();
closeTabCommand.Executed += (sender, args) => _tabs.Tabs.Remove(_tabs.Tabs.SelectedPage);
closeTabCommand.Executed += (sender, args) =>
{
_tabs.Tabs_PageClosed(_tabs, new(_tabs.Tabs.SelectedPage));
_tabs.Tabs.Remove(_tabs.Tabs.SelectedPage);
};
Items.Add(new ButtonMenuItem
{
Text = "Close",
Expand All @@ -31,6 +35,7 @@ public TabContextMenu(EditorTabsPanel tabs, ILogger log) : base()
int index = _tabs.Tabs.SelectedIndex;
for (int i = _tabs.Tabs.Pages.Count - 1; i > index; i--)
{
_tabs.Tabs_PageClosed(_tabs, new(_tabs.Tabs.Pages[i]));
_tabs.Tabs.Remove(_tabs.Tabs.Pages[i]);
}
};
Expand All @@ -43,7 +48,11 @@ public TabContextMenu(EditorTabsPanel tabs, ILogger log) : base()
Command closeAllTabsCommand = new();
closeAllTabsCommand.Executed += (sender, args) =>
{
_tabs.Tabs.Pages.Clear();
for (int i = _tabs.Tabs.Pages.Count - 1; i >= 0; i--)
{
_tabs.Tabs_PageClosed(_tabs, new(_tabs.Tabs.Pages[i]));
_tabs.Tabs.Remove(_tabs.Tabs.Pages[i]);
}
};
Items.Add(new ButtonMenuItem
{
Expand All @@ -55,7 +64,11 @@ public TabContextMenu(EditorTabsPanel tabs, ILogger log) : base()
closeAllTabsButThisCommand.Executed += (sender, args) =>
{
DocumentPage @this = _tabs.Tabs.SelectedPage;
_tabs.Tabs.Pages.Clear();
for (int i = _tabs.Tabs.Pages.Count - 1; i >= 0; i--)
{
_tabs.Tabs_PageClosed(_tabs, new(_tabs.Tabs.Pages[i]));
_tabs.Tabs.Remove(_tabs.Tabs.Pages[i]);
}
_tabs.Tabs.Pages.Add(@this);
};
Items.Add(new ButtonMenuItem
Expand Down

0 comments on commit 8516ab2

Please sign in to comment.