Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tab drag and drop #3478

Merged
merged 5 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/TabRowControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ the MIT License. See LICENSE in the project root for license information. -->
HorizontalContentAlignment="Stretch"
IsAddTabButtonVisible="false"
TabWidthMode="SizeToContent"
CanReorderTabs="False"
CanDragTabs="False"
AllowDropTabs="False">
CanReorderTabs="True"
CanDragTabs="True"
AllowDropTabs="True">

<mux:TabView.TabStripFooter>
<mux:SplitButton
Expand Down
72 changes: 54 additions & 18 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ namespace winrt::TerminalApp::implementation
_tabContent = this->TabContent();
_tabRow = this->TabRow();
_tabView = _tabRow.TabView();
_rearranging = false;

_tabView.TabDragStarting([this](auto&& /*o*/, auto&& /*a*/) {
_rearranging = true;
_rearrangeFrom = -1;
clarkezone marked this conversation as resolved.
Show resolved Hide resolved
_rearrangeTo = -1;
});

_tabView.TabDragCompleted([this](auto&& /*o*/, auto&& /*a*/) {
if (_rearrangeFrom >= 0 && _rearrangeTo >= 0 && _rearrangeTo != _rearrangeFrom)
{
auto tab = _tabs.at(_rearrangeFrom);
_tabs.erase(_tabs.begin() + _rearrangeFrom);
_tabs.insert(_tabs.begin() + _rearrangeTo, tab);
}

_rearranging = false;
_rearrangeFrom = -1;
_rearrangeTo = -1;
});

auto tabRowImpl = winrt::get_self<implementation::TabRowControl>(_tabRow);
_newTabButton = tabRowImpl->NewTabButton();
Expand Down Expand Up @@ -1175,8 +1195,21 @@ namespace winrt::TerminalApp::implementation
// Arguments:
clarkezone marked this conversation as resolved.
Show resolved Hide resolved
// - sender: the control that originated this event
// - eventArgs: the event's constituent arguments
void TerminalPage::_OnTabItemsChanged(const IInspectable& /*sender*/, const Windows::Foundation::Collections::IVectorChangedEventArgs& /*eventArgs*/)
void TerminalPage::_OnTabItemsChanged(const IInspectable& /*sender*/, const Windows::Foundation::Collections::IVectorChangedEventArgs& eventArgs)
clarkezone marked this conversation as resolved.
Show resolved Hide resolved
{
if (_rearranging)
{
if (eventArgs.CollectionChange() == Windows::Foundation::Collections::CollectionChange::ItemRemoved)
{
_rearrangeFrom = eventArgs.Index();
}

if (eventArgs.CollectionChange() == Windows::Foundation::Collections::CollectionChange::ItemInserted)
{
_rearrangeTo = eventArgs.Index();
}
}

_UpdateTabView();
}

Expand All @@ -1196,34 +1229,37 @@ namespace winrt::TerminalApp::implementation

// Method Description:
// - Responds to the TabView control's Selection Changed event (to move a
// new terminal control into focus.)
// new terminal control into focus.) when not in in the middle of a tab rearrangement
// Arguments:
// - sender: the control that originated this event
// - eventArgs: the event's constituent arguments
void TerminalPage::_OnTabSelectionChanged(const IInspectable& sender, const WUX::Controls::SelectionChangedEventArgs& /*eventArgs*/)
{
auto tabView = sender.as<MUX::Controls::TabView>();
auto selectedIndex = tabView.SelectedIndex();

// Unfocus all the tabs.
for (auto tab : _tabs)
if (!_rearranging)
{
tab->SetFocused(false);
}
auto tabView = sender.as<MUX::Controls::TabView>();
auto selectedIndex = tabView.SelectedIndex();

if (selectedIndex >= 0)
{
try
// Unfocus all the tabs.
for (auto tab : _tabs)
{
tab->SetFocused(false);
}

if (selectedIndex >= 0)
{
auto tab = _tabs.at(selectedIndex);
try
{
auto tab = _tabs.at(selectedIndex);

_tabContent.Children().Clear();
_tabContent.Children().Append(tab->GetRootElement());
_tabContent.Children().Clear();
_tabContent.Children().Append(tab->GetRootElement());

tab->SetFocused(true);
_titleChangeHandlers(*this, Title());
tab->SetFocused(true);
_titleChangeHandlers(*this, Title());
}
CATCH_LOG();
}
CATCH_LOG();
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CascadiaSettings.h"
#include "Profile.h"

#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
Expand Down Expand Up @@ -60,6 +61,10 @@ namespace winrt::TerminalApp::implementation

bool _isFullscreen{ false };

bool _rearranging;
int _rearrangeFrom;
int _rearrangeTo;

void _ShowAboutDialog();
void _ShowCloseWarningDialog();

Expand Down