Skip to content

Conversation

pmiossec
Copy link
Member

@pmiossec pmiossec commented Oct 17, 2023

Proposed changes

In scripts command line arguments, the user is allows to:

  • specify multiple user inputs
  • specify a label as a reminder of what is requested (that will appear in the title of the input popup)
  • specify or build a default value (that the user could modify before validating)

Example: bundle create {{UserInput:Bundle filename|{cLocalBranch}.bundle|}} -{UserInput:Nb commits||} {cLocalBranch}

2 inputs will be requested.

Screenshots

Before

After

image

Test methodology

  • Unit tests
  • Manual

Test environment(s)

  • Git Extensions 33.33.33
  • Build d735064 (Dirty)
  • Git 2.42.0.windows.2
  • Microsoft Windows NT 10.0.22621.0
  • .NET 6.0.21
  • DPI 96dpi (no scaling)
  • Portable: False
  • Microsoft.WindowsDesktop.App Versions
    Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Merge strategy

I agree that the maintainer Rebase merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned pmiossec Oct 17, 2023
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

+1

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

As already mentioned, multiple use of one input value is a very useful feature - e,g. "command {UserInput:A=a} ... {UserInput:B=b} ... {UserInput:A} ...".
Omitted label, i.e. empty string, automatically brings downwards compatibility.

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Oct 31, 2023
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Oct 31, 2023
@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 2, 2023
@pmiossec pmiossec force-pushed the script_user_input_improvement branch from d735064 to 849353d Compare November 6, 2023 12:15
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 6, 2023
@pmiossec pmiossec force-pushed the script_user_input_improvement branch 2 times, most recently from 46aaf55 to 394ae7f Compare November 6, 2023 14:12
@pmiossec
Copy link
Member Author

pmiossec commented Nov 6, 2023

I think I fixed all the points raised. Changes undo a lot of changes so I have rewritten the history (sorry) so that it's clearer now.

@mstv "multiple use of one input value" is now working as you expect.

@mstv & @RussKie I tried to implement the syntax {UserInput:label=default value} you both proposed.
The RegEx is now a lot more complex to understand but it seems to work reasonably well...

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

LGTM in a quick review, have not run yet

@pmiossec pmiossec force-pushed the script_user_input_improvement branch 2 times, most recently from bff98e0 to 098f919 Compare November 7, 2023 08:32
@pmiossec pmiossec force-pushed the script_user_input_improvement branch from 098f919 to 29d2b40 Compare November 8, 2023 10:51
@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 9, 2023
@pmiossec pmiossec force-pushed the script_user_input_improvement branch from 29d2b40 to b979616 Compare November 9, 2023 09:06
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 9, 2023
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

The parser seems to work well. 👍

Cancellation of the input dialog should throw a (silent) OperationAbortedException.
Esc should deselect the selection if any, else cancel the input.

The label should be used as label (perhaps with ":" appended), but not as caption.
The caption should rather be User input for script {name}.

@pmiossec pmiossec force-pushed the script_user_input_improvement branch from a087ed2 to dd79aeb Compare November 10, 2023 11:34
@pmiossec
Copy link
Member Author

The parser seems to work well. 👍

Cancellation of the input dialog should throw a (silent) OperationAbortedException. Esc should deselect the selection if any, else cancel the input.

The label should be used as label (perhaps with ":" appended), but not as caption. The caption should rather be User input for script {name}.

Done.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

final nits

@pmiossec pmiossec force-pushed the script_user_input_improvement branch 2 times, most recently from 669e8bf to 3b27632 Compare November 11, 2023 11:30
DialogResult result = prompt.ShowDialog(owner);
if (result != DialogResult.OK)
{
throw new OperationCanceledException();
Copy link
Member

Choose a reason for hiding this comment

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

😨 Why are we throwing here?
It looks as though we're using exceptions for the flow control, which is a code smell.
Throwing exceptions is quite expensive, and they represent an exceptional state, which user cancelling the dialog isn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

Throwing exceptions is quite expensive

Performance doesn't matter here because the exception is thrown only one time to display a user popup.

and they represent an exceptional state, which user cancelling the dialog isn't.

I think the cancelling of the dialog is exceptional otherwise we would have already an issue opened because the error popup is absolutely not good 🤣

I really think a refactoring here is overkill as the method is returning at the moment only a value and we will have to refactor it to return also a state enum (Success/Abort/UserAbort), handle well this state for all arguments and handle it in the calling code. I predict more than 100 lines of new code and changes just to handle the case of 2 arguments UserFile and UserInput that ask inputs from user and that a bad/no input should abort the script. That's the handling of these 2 arguments and the possibility to abort which is "exceptional" 😉

I really don't want to go this way....

DialogResult result = prompt.ShowDialog(owner);
if (result == DialogResult.Cancel)
{
throw new OperationCanceledException();
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines 153 to 227
catch (OperationCanceledException)
{
MessageBox.Show(owner, TranslatedStrings.ScriptUserCanceledRun, TranslatedStrings.ScriptText, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this at all?

Copy link
Member Author

@pmiossec pmiossec Nov 11, 2023

Choose a reason for hiding this comment

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

Because otherwise the user have a frightening error message dialog that absolutely doesn't correspond to the reason why we abort the launch of the script:

image

Copy link
Member

@RussKie RussKie Nov 12, 2023

Choose a reason for hiding this comment

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

To me this is a confirmation that we're doing it incorrectly :)
I think this is a misplaced responsibility, please have a look at 4b772c4 (disclaimer: I just moved code around without running it).

Copy link
Member Author

Choose a reason for hiding this comment

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

@RussKie Not really convinced but OK for me. Have a look at other changes required by this solution and provide feedback before I spend time to adapt tests (because with this solution, it's now less straightforward and I don't want to spend too much time on it if later adaptations are needed).

Copy link
Member Author

Choose a reason for hiding this comment

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

@RussKie Friendly reminder 😉

@ghost ghost added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 11, 2023
@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Nov 11, 2023
@pmiossec pmiossec requested a review from RussKie November 17, 2023 10:08
@RussKie
Copy link
Member

RussKie commented Nov 17, 2023 via email

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

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

👍 modulo the question about the tests

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

just a little cleanup yet

@pmiossec pmiossec force-pushed the script_user_input_improvement branch from 94d2266 to 12a2088 Compare November 22, 2023 15:50
Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

nits

@pmiossec pmiossec force-pushed the script_user_input_improvement branch from 12a2088 to 903c2cd Compare November 23, 2023 08:03
by having the possibility to provide the popup a meaningful title
and a default value (that could be an argument also)

Note: UserInput with arguments replace only one specific occurrence
contrary to `{UserInput}` that ask user for a value and replace all tokens with the value provided

Example: :
* hard-coded label and default value: `{UserInput:user label=a default value}`
* hard-coded label and no default value: `{UserInput:user label}`
* use an existing token as (part of ) a default value: `{UserInput:Bundle filename={cLocalBranch}.bundle}`
* Replace all user inputs with same label like in: "{UserInput:input label1=value}_{UserInput:input label1}_{{UserInput:input label1}}"

+ add test for {UserInput} token (and similar {UserFiles} token)

that need to introduce ISimplePromptCreator
that takes care of creating the dialog
to be able to fake it in unit tests

+ SimplePrompt UX improvements

* Script run canceled if user close the form (with a friendly "Script run canceled by user." information popup)
* User is able to close the form with Esc key (1st press deselect the selection if any)
* label defined by user is no more displayed in the form caption but on the input label
* Caption display the name of the script run: "User input for script '{name}'"

+ Move handling of {UserInput} and {UserFiles} tokens, that could be cancelled by user,
     earlier in the argument processing (in ScriptManager.ScriptRunner)
    & handle difference between user cancel and abort for parsing error
@pmiossec pmiossec force-pushed the script_user_input_improvement branch from 903c2cd to a1bc8a6 Compare November 23, 2023 08:10
@RussKie RussKie merged commit eeaf3c1 into gitextensions:master Nov 24, 2023
@ghost ghost added this to the vNext milestone Nov 24, 2023
@pmiossec pmiossec deleted the script_user_input_improvement branch November 24, 2023 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants