Skip to content

Commit

Permalink
and with that, we're ready to cleanup for review.
Browse files Browse the repository at this point in the history
  2 TODOs left
  • Loading branch information
zadjii-msft committed Feb 10, 2023
1 parent 4548729 commit 7660937
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
8 changes: 8 additions & 0 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
return *result;
}
}
else if (targetWindow == WindowingBehaviorUseNone)
{
// In this case, the targetWindow was UseNone, which means that we
// want to make a message box, but otherwise not make a Terminal
// window.
auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(false);
return *result;
}

// If we get here, we couldn't find an existing window. Make a new one.
TraceLoggingWrite(g_hRemotingProvider,
Expand Down
11 changes: 9 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ namespace winrt::TerminalApp::implementation
{
if (!appArgs.GetExitMessage().empty())
{
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNew);
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNone);
}

const std::string parsedTarget{ appArgs.GetTargetWindow() };
Expand Down Expand Up @@ -644,7 +644,7 @@ namespace winrt::TerminalApp::implementation
// create a new window. Then, in that new window, we'll try to set the
// StartupActions, which will again fail, returning the correct error
// message.
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNew);
return winrt::make<FindTargetWindowResult>(WindowingBehaviorUseNone);
}

Windows::Foundation::Collections::IMapView<Microsoft::Terminal::Control::KeyChord, Microsoft::Terminal::Settings::Model::Command> AppLogic::GlobalHotkeys()
Expand Down Expand Up @@ -699,4 +699,11 @@ namespace winrt::TerminalApp::implementation

ApplicationState::SharedInstance().PersistedWindowLayouts(winrt::single_threaded_vector(std::move(converted)));
}

TerminalApp::ParseCommandlineResult AppLogic::GetParseCommandlineMessage(array_view<const winrt::hstring> args)
{
::TerminalApp::AppCommandlineArgs _appArgs;
const auto r = _appArgs.ParseArgs(args);
return TerminalApp::ParseCommandlineResult{ winrt::to_hstring(_appArgs.GetExitMessage()), r};
}
}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace winrt::TerminalApp::implementation

TerminalApp::TerminalWindow CreateNewWindow();

TerminalApp::ParseCommandlineResult GetParseCommandlineMessage(array_view<const winrt::hstring> args);

TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::SettingsLoadEventArgs);

private:
Expand Down
11 changes: 10 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace TerminalApp
String WindowName { get; };
};

struct ParseCommandlineResult
{
String Message;
Int32 ExitCode;
};


// See IDialogPresenter and TerminalPage's DialogPresenter for more
// information.
[default_interface] runtimeclass AppLogic
Expand Down Expand Up @@ -40,7 +47,9 @@ namespace TerminalApp

TerminalWindow CreateNewWindow();

Windows.Foundation.Collections.IMapView<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();
ParseCommandlineResult GetParseCommandlineMessage(String[] args);

IMapView<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();

event Windows.Foundation.TypedEventHandler<Object, SettingsLoadEventArgs> SettingsChanged;

Expand Down
25 changes: 15 additions & 10 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ void AppHost::SetTaskbarProgress(const winrt::Windows::Foundation::IInspectable&
}
}

void AppHost::s_DisplayMessageBox(const winrt::TerminalApp::ParseCommandlineResult& result)
{
const auto displayHelp = result.ExitCode == 0;
const auto messageTitle = displayHelp ? IDS_HELP_DIALOG_TITLE : IDS_ERROR_DIALOG_TITLE;
const auto messageIcon = displayHelp ? MB_ICONWARNING : MB_ICONERROR;
// TODO:GH#4134: polish this dialog more, to make the text more
// like msiexec /?
MessageBoxW(nullptr,
result.Message.data(),
GetStringResource(messageTitle).data(),
MB_OK | messageIcon);
}

// Method Description:
// - Retrieve any commandline args passed on the commandline, and pass them to
// the WindowManager, to ask if we should become a window process.
Expand Down Expand Up @@ -171,19 +184,11 @@ void AppHost::_HandleCommandlineArgs()
const auto message = _windowLogic.ParseCommandlineMessage();
if (!message.empty())
{
const auto displayHelp = result == 0;
const auto messageTitle = displayHelp ? IDS_HELP_DIALOG_TITLE : IDS_ERROR_DIALOG_TITLE;
const auto messageIcon = displayHelp ? MB_ICONWARNING : MB_ICONERROR;
// TODO:GH#4134: polish this dialog more, to make the text more
// like msiexec /?
MessageBoxW(nullptr,
message.data(),
GetStringResource(messageTitle).data(),
MB_OK | messageIcon);
AppHost::s_DisplayMessageBox({ message, result});

if (_windowLogic.ShouldExitEarly())
{
ExitProcess(result);
ExitThread(result);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class AppHost

bool HasWindow();

static void s_DisplayMessageBox(const winrt::TerminalApp::ParseCommandlineResult& message);

winrt::TerminalApp::TerminalWindow Logic();

private:
Expand Down
13 changes: 11 additions & 2 deletions src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ WindowEmperor::~WindowEmperor()
// hosts, xaml sources, everything, seem to get closed and dtor'd before
// this point. Theoretically, we shouldn't event have leak reporting enabled
// for this thread. It's a real thinker.
//
// I need someone to help take a look at this with me.

_app.Close();
_app = nullptr;
Expand Down Expand Up @@ -97,8 +99,6 @@ bool WindowEmperor::HandleCommandlineArgs()

const auto result = _manager.ProposeCommandline2(eventArgs);

// TODO! createWindow is false in cases like wt --help. Figure that out.

if (result.ShouldCreateWindow())
{
CreateNewWindowThread(Remoting::WindowRequestedArgs{ result, eventArgs }, true);
Expand All @@ -109,6 +109,15 @@ bool WindowEmperor::HandleCommandlineArgs()

_becomeMonarch();
}
else
{
const auto res = _app.Logic().GetParseCommandlineMessage(eventArgs.Commandline());
if (!res.Message.empty())
{
AppHost::s_DisplayMessageBox(res);
ExitThread(res.ExitCode);
}
}

return result.ShouldCreateWindow();
}
Expand Down

1 comment on commit 7660937

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (15)
APeasant
Apphost
applogic
backchannel
becuase
chould
connectecd
definted
dxgidebug
Faile
fuction
initilized
propogating
RLO
vaugely
Previously acknowledged words that are now absent CLA demoable everytime Hirots inthread reingest unmark :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/migrie/oop/3/ainulindale branch (ℹ️ how do I use this?):

curl -s -S -L 'https://github.com/raw/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/4146906326/attempts/1'
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.