Skip to content

Commit

Permalink
more cleanup for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Dec 19, 2019
1 parent 8f7e442 commit 23f2cd2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 31 deletions.
8 changes: 0 additions & 8 deletions src/cascadia/TerminalApp/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,4 @@ namespace winrt::TerminalApp::factory_implementation
{
BASIC_FACTORY(ActionEventArgs);
BASIC_FACTORY(NewTerminalArgs);

BASIC_FACTORY(CopyTextArgs);
BASIC_FACTORY(NewTabArgs);
BASIC_FACTORY(SwitchToTabArgs);
BASIC_FACTORY(ResizePaneArgs);
BASIC_FACTORY(MoveFocusArgs);
BASIC_FACTORY(AdjustFontSizeArgs);
BASIC_FACTORY(SplitPaneArgs);
}
7 changes: 0 additions & 7 deletions src/cascadia/TerminalApp/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,36 @@ namespace TerminalApp

[default_interface] runtimeclass CopyTextArgs : IActionArgs
{
CopyTextArgs();
Boolean TrimWhitespace { get; };
};

[default_interface] runtimeclass NewTabArgs : IActionArgs
{
NewTabArgs();
NewTerminalArgs TerminalArgs { get; };
};

[default_interface] runtimeclass SwitchToTabArgs : IActionArgs
{
SwitchToTabArgs();
Int32 TabIndex { get; };
};

[default_interface] runtimeclass ResizePaneArgs : IActionArgs
{
ResizePaneArgs();
Direction Direction { get; };
};

[default_interface] runtimeclass MoveFocusArgs : IActionArgs
{
MoveFocusArgs();
Direction Direction { get; };
};

[default_interface] runtimeclass AdjustFontSizeArgs : IActionArgs
{
AdjustFontSizeArgs();
Int32 Delta { get; };
};

[default_interface] runtimeclass SplitPaneArgs : IActionArgs
{
SplitPaneArgs();
SplitState SplitStyle { get; };
NewTerminalArgs TerminalArgs { get; };
};
Expand Down
12 changes: 12 additions & 0 deletions src/cascadia/TerminalApp/AppCommandlineArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,18 @@ const std::string& AppCommandlineArgs::GetExitMessage()
return _exitMessage;
}

// Method Description:
// - Ensure that the first command in our list of actions is a NewTab action.
// This makes sure that if the user passes a commandline like "wt split-pane
// -H", we _first_ create a new tab, so there's always at least one tab.
// - If the first command in our queue of actions is a NewTab action, this does
// nothing.
// - This should only be called once - if the first NewTab action is popped from
// our _startupActions, calling this again will add another.
// Arguments:
// - <none>
// Return Value:
// - <none>
void AppCommandlineArgs::ValidateStartupCommands()
{
// If we parsed no commands, or the first command we've parsed is not a new
Expand Down
29 changes: 26 additions & 3 deletions src/cascadia/TerminalApp/Commandline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

using namespace TerminalApp;

Commandline::~Commandline()
{
_resetArgv();
}

size_t Commandline::Argc() const
{
return _wargs.size();
Expand Down Expand Up @@ -65,6 +70,14 @@ char** Commandline::BuildArgv()
return _argv;
}

// Method Description:
// - Add the given arg to the list of args for this commandline. If the arg has
// an escaped delimiter ('\;') in it, we'll de-escape it, so the processed
// Commandline will have it as just a ';'.
// Arguments:
// - nextArg: The string to add as an arg to the commandline. This string may contain spaces.
// Return Value:
// - <none>
void Commandline::AddArg(const std::wstring& nextArg)
{
if (_argv)
Expand All @@ -84,11 +97,21 @@ void Commandline::AddArg(const std::wstring& nextArg)
_wargs.emplace_back(modifiedArg);
}

// Method Description:
// - Delete our previously constructed _argv array
// Arguments:
// - <none>
// Return Value:
// - <none>
void Commandline::_resetArgv()
{
for (int i = 0; i < Argc(); i++)
if (_argv)
{
delete[] _argv[i];
for (int i = 0; i < Argc(); i++)
{
delete[] _argv[i];
}
delete[] _argv;
_argv = 0;
}
delete[] _argv;
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/Commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace TerminalApp
class TerminalApp::Commandline
{
public:
~Commandline();

static constexpr std::wstring_view Delimiter{ L";" };
static constexpr std::wstring_view EscapedDelimiter{ L"\\;" };

Expand Down
17 changes: 6 additions & 11 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ namespace winrt::TerminalApp::implementation

void TerminalPage::Create()
{
// std::vector<const wchar_t*> rawCommands{
// L"wt.exe", L"new-tab", L"cmd.exe", L";", L"split-pane", L"-V", L"-p", L"Ubuntu", L";", L"new-tab"
// };
// _ParseArgs(static_cast<int>(rawCommands.size()), rawCommands.data());

// Hookup the key bindings
_HookupKeyBindings(_settings->GetKeybindings());

Expand Down Expand Up @@ -147,7 +142,7 @@ namespace winrt::TerminalApp::implementation
// This will kick off a chain of events to perform each startup
// action. As each startup action is completed, the next will be
// fired.
_ProcessNextStartupAction();
_processNextStartupAction();
}
}

Expand All @@ -158,7 +153,7 @@ namespace winrt::TerminalApp::implementation
// - <none>
// Return Value:
// - <none>
void TerminalPage::_ProcessNextStartupAction()
void TerminalPage::_processNextStartupAction()
{
// If there are no actions left, do nothing.
if (_appArgs.GetStartupActions().size() == 0)
Expand All @@ -177,7 +172,7 @@ namespace winrt::TerminalApp::implementation
page->_actionDispatch->DoAction(nextAction);

// Kick off the next action to be handled (if necessary)
page->_ProcessNextStartupAction();
page->_processNextStartupAction();
}
});
}
Expand Down Expand Up @@ -1473,10 +1468,10 @@ namespace winrt::TerminalApp::implementation
// - args: an array of strings to process as a commandline. These args can contain spaces
// Return Value:
// - the result of the first command who's parsing returned a non-zero code,
// or 0. (see TerminalPage::_ParseArgs)
// or 0. (see TerminalPage::_parseArgs)
int32_t TerminalPage::SetStartupCommandline(winrt::array_view<const hstring> args)
{
return _ParseArgs(args);
return _parseArgs(args);
}

// Method Description:
Expand All @@ -1491,7 +1486,7 @@ namespace winrt::TerminalApp::implementation
// - argv: a c-style array of wchar_t strings. These strings can include spaces in them.
// Return Value:
// - 0 if the commandline was successfully parsed
int TerminalPage::_ParseArgs(winrt::array_view<const hstring>& args)
int TerminalPage::_parseArgs(winrt::array_view<const hstring>& args)
{
auto commands = ::TerminalApp::AppCommandlineArgs::BuildCommands(args);

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ namespace winrt::TerminalApp::implementation
winrt::com_ptr<ShortcutActionDispatch> _actionDispatch{ winrt::make_self<ShortcutActionDispatch>() };

::TerminalApp::AppCommandlineArgs _appArgs;
int _ParseArgs(winrt::array_view<const hstring>& args);
void _ProcessNextStartupAction();
int _parseArgs(winrt::array_view<const hstring>& args);
void _processNextStartupAction();

void _ShowAboutDialog();
void _ShowCloseWarningDialog();
Expand Down

0 comments on commit 23f2cd2

Please sign in to comment.