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
RevisionDiff: Move out non GUI to RevisionDiffController #4112
RevisionDiff: Move out non GUI to RevisionDiffController #4112
Conversation
…-browse-artificial-stage Refactoring in master so changes in GitUI/CommandsDialogs/FormBrowse.Designer.cs and GitUI/CommandsDialogs/FormBrowse.cs reverted
Reimplementation after refactoring in master to RevisionDiffThe implementation can currently not refresh the RevisionGrid.
…-browse-artificial-stage
Requested as part of gitextensions#4106 and other The files are still tightly coupled with _revisionGrid shared For instance Module must be extracted from revisionGrid, or pass revisiongrid.Module at every call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems as though the purpose of the controller is unclear to you.
We need the controller to decouple the "thinking" (business logic) from the presentation (UI). This separation provides a number of benefits, such as:
- testability - we can verify the implementation
- documentation/assurance - this pretty much follows from the previous point - tests allow to capture the requirements and assumptions used during the implementation, and
- UI portability or plugability - (in the ideal world) we could use the controller for a completely different UI implementation (e.g. web, wpf, etc). The UI layer provides necessary interaction elements and all the logic behind those elements is abstracted by the controller.
I hope it makes sense.
I've pushed a sample of what I envisaged when suggested moving the logic into the controller. It isn't a complete solution by any means (i.e. missing argument validations, tests etc), but is a good start.
@@ -42,6 +43,10 @@ public RevisionDiff() | |||
DiffText.Font = AppSettings.DiffFont; | |||
|
|||
GotFocus += (s, e) => DiffFiles.Focus(); | |||
Load += (s, e) => | |||
{ | |||
_revisionDiffController = new RevisionDiffController(Module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing Module object does not make sense, it is not updated when the RevisionDiff Module is updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module is not required, I put it as an example.
it is not updated when the RevisionDiff Module is updated
that's a very good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not updated when the RevisionDiff Module is updated
I've checked it, Module
always contains the current information when switching between git repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The working for was not updated for me.
@@ -633,16 +664,6 @@ private void saveAsToolStripMenuItem1_Click(object sender, EventArgs e) | |||
} | |||
} | |||
|
|||
|
|||
private bool DeleteSelectedDiffFiles() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK to remove, just a comment: This was purposely not removed as I want to have Keyboard shortcut here. A refrence from FormBrowse is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR is concentrating on moving logic out of the UI.
a following PR can concentrate on adding keyboard shortcuts
//Many options have no meaning for artificial commits or submodules | ||
//Hide the obviously no action options when single selected, handle them in actions if multi select | ||
|
||
// disable items that need exactly one selected item | ||
bool isExactlyOneItemSelected = DiffFiles.SelectedItems.Count() == 1; | ||
var isCombinedDiff = isExactlyOneItemSelected && | ||
DiffFiles.CombinedDiff.Text == DiffFiles.SelectedItemParent; | ||
var isCombinedDiff = isExactlyOneItemSelected && DiffFiles.CombinedDiff.Text == DiffFiles.SelectedItemParent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider this to leave too much logic in the GUI layer. This will not separate the layers, just involve two files instead of one.
@@ -706,7 +726,6 @@ private void diffEditFileToolStripMenuItem_Click(object sender, EventArgs e) | |||
//TBD RefreshRevisions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some solution to refresh the difflist and revisions is needed here.
@RussKie I believe the suggestion you implemented is just making the implementation more complicated:
I can live with the changes (except for passing Module), will just not push for such changes. |
Ideally the
As per #4106 (review) I am expecting a refactor to increase maintainability of the new functionality.
In the current codebase we are maintaining only one file but the price of maintenance is staggering.
I respectfully disagree, tests are anything but meaningless. For example:
This is complex for a simple one/two-line property. It is very hard to reason about these implementations and to make changes. |
What is missing then? openWithDifftoolToolStripMenuItem_DropDownOpening? (Most logic will remain RevisionDiff though.) I consider the test case meaningless because the logic is still in RevisionDiff. The test is independent of the functionality. I will look at some sample tests though. |
how so? RevisionDiff collects the data and passes it to RevisionDiffController to make decisions My proposal isn't perfect nor complete, it is meant as a talking point. There is still a room for improvement (i.e. signatures look very similar - can be refactored further). |
…how* to RevisionDiffController
@RussKie I want you to be happy, you (and current/previous maintainers) are doing a great job. So I can do what you suggest, but my arguments against doing it the way it is done:
Adding tests will take a little longer (but will come), partly because I have not added tests here before, partly because I do not have a plan for good tests, partly because this does not engage me. |
Side note: I have started to write tests, but that is slow... |
I think tests can be generialised to something like:
- if selected a single revision and a single diff item I can see the
following menus and can't see the others
- if selected a single revision and a single submodule then...
- if selected a single revision and multiple diff items some of which
submodules then....
And so on....
…On 07/11/2017 11:02 PM, "Gerhard Olsson" ***@***.***> wrote:
Side note: I have started to write tests, but that is slow...
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#4112 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEMyXnb_spo680Qha4zFh87pEHsdd551ks5s0EbbgaJpZM4QL7qb>
.
|
There are at least 2^7 combinations so all combinations cannot be tested... |
If we can cover few main cases it will still be a win
…On 08/11/2017 7:32 AM, "Gerhard Olsson" ***@***.***> wrote:
There are at least 2^7 combinations so all combinations cannot be tested...
I will think about it.
(So far I have been looking at how to write a test case than what to
write. It slows be down some so I rather take this in the background
otherwise everything will take like forever.)
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#4112 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEMyXrSsnyJS7yAwPQJxqUriglFRA4-aks5s0L5EgaJpZM4QL7qb>
.
|
On top of #4087 (only last commit specific)
Requested as part of #4106 #4089, #4087, #4092 by @RussKie
The files are still tightly coupled with for instance _revisionGrid shared
Some calls like resetFileToToolStripMenuItem_DropDownOpening would just have resulted in code duplication
The Controller is not testable right now - but t is a start at least
For instance Module must be extracted from revisionGrid, or pass revisiongrid.Module at every call
Path.Combine is not swapped (4 out of 5 calls applicable) could have been replaced but I feel that this limits the readability and just increases code size.
Changes proposed in this pull request:
Screenshots before and after (if PR changes UI):
How did I test this code:
Has been tested on (remove any that don't apply):