Skip to content

Commit

Permalink
Add delete lines in Merge Viewer
Browse files Browse the repository at this point in the history
Prevent entering empty text in conflict solver edit mode
  • Loading branch information
bcssov committed Apr 17, 2020
1 parent e390104 commit 46ef41d
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 15 deletions.
3 changes: 2 additions & 1 deletion publish/publish-linux-x64.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cd ..
dotnet build --configuration Release
dotnet publish src\IronyModManager\IronyModManager.csproj /p:PublishProfile=src\IronyModManager\Properties\PublishProfiles\linux-x64.pubxml --configuration Release
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\linux-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\linux-x64\" /Y /S /D
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\linux-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\linux-x64\" /Y /S /D
cd publish
3 changes: 2 additions & 1 deletion publish/publish-osx-x64.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cd ..
dotnet build --configuration Release
dotnet publish src\IronyModManager\IronyModManager.csproj /p:PublishProfile=src\IronyModManager\Properties\PublishProfiles\osx-x64.pubxml --configuration Release
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\osx-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\osx-x64\" /Y /S /D
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\osx-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\osx-x64\" /Y /S /D
cd publish
3 changes: 2 additions & 1 deletion publish/publish-win-x64.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cd ..
dotnet build --configuration Release
dotnet publish src\IronyModManager\IronyModManager.csproj /p:PublishProfile=src\IronyModManager\Properties\PublishProfiles\win-x64.pubxml --configuration Release
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\win-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\win-x64\" /Y /S /D
xcopy "src\IronyModManager\bin\Release\netcoreapp3.1\win-x64\*.dll" "src\IronyModManager\bin\Release\netcoreapp3.1\publish\win-x64\" /Y /S /D
cd publish
1 change: 1 addition & 0 deletions src/IronyModManager.Shared/LocalizationResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static class ContextMenu
public const string MoveDown = Prefix + "MoveDown";
public const string Edit = Prefix + "Edit";
public const string CopyText = Prefix + "CopyText";
public const string Delete = Prefix + "Delete";
}
public static class EditorContextMenu
{
Expand Down
3 changes: 2 additions & 1 deletion src/IronyModManager/Localization/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"MoveUp": "Nach oben gehen",
"MoveDown": "Sich abwärts bewegen",
"Edit": "Bearbeiten Sie dies",
"CopyText": "Text kopieren"
"CopyText": "Text kopieren",
"Delete": "Löschen"
},
"EditorContextMenu": {
"Copy": "Kopieren",
Expand Down
3 changes: 2 additions & 1 deletion src/IronyModManager/Localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"MoveUp": "Move Up",
"MoveDown": "Move Down",
"Edit": "Edit",
"CopyText": "Copy Text"
"CopyText": "Copy Text",
"Delete": "Delete"
},
"EditorContextMenu": {
"Copy": "Copy",
Expand Down
3 changes: 2 additions & 1 deletion src/IronyModManager/Localization/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"MoveUp": "Pomakni gore",
"MoveDown": "Pomakni dolje",
"Edit": "Uredi",
"CopyText": "Kopiraj Tekst"
"CopyText": "Kopiraj Tekst",
"Delete": "Obriši"
},
"EditorContextMenu": {
"Copy": "Kopiraj",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 03-20-2020
//
// Last Modified By : Mario
// Last Modified On : 04-16-2020
// Last Modified On : 04-17-2020
// ***********************************************************************
// <copyright file="MergeViewerControlViewModel.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -87,12 +87,6 @@ public MergeViewerControlViewModel(IUrlAction urlAction)

#region Properties

/// <summary>
/// Gets or sets a value indicating whether [editing yaml].
/// </summary>
/// <value><c>true</c> if [editing yaml]; otherwise, <c>false</c>.</value>
public virtual bool EditingYaml { get; set; }

/// <summary>
/// Gets or sets the cancel.
/// </summary>
Expand Down Expand Up @@ -158,6 +152,25 @@ public MergeViewerControlViewModel(IUrlAction urlAction)
/// <value>The copy this command.</value>
public virtual ReactiveCommand<bool, Unit> CopyThisCommand { get; protected set; }

/// <summary>
/// Gets or sets the current edit text.
/// </summary>
/// <value>The current edit text.</value>
public virtual string CurrentEditText { get; set; }

/// <summary>
/// Gets or sets the delete text.
/// </summary>
/// <value>The delete text.</value>
[StaticLocalization(LocalizationResources.Conflict_Solver.ContextMenu.Delete)]
public virtual string DeleteText { get; protected set; }

/// <summary>
/// Gets or sets the delete text command.
/// </summary>
/// <value>The delete text command.</value>
public virtual ReactiveCommand<bool, Unit> DeleteTextCommand { get; protected set; }

/// <summary>
/// Gets or sets a value indicating whether [editing left].
/// </summary>
Expand All @@ -176,6 +189,12 @@ public MergeViewerControlViewModel(IUrlAction urlAction)
/// <value><c>true</c> if [editing text]; otherwise, <c>false</c>.</value>
public virtual bool EditingText { get; protected set; }

/// <summary>
/// Gets or sets a value indicating whether [editing yaml].
/// </summary>
/// <value><c>true</c> if [editing yaml]; otherwise, <c>false</c>.</value>
public virtual bool EditingYaml { get; set; }

/// <summary>
/// Gets or sets the editor copy.
/// </summary>
Expand Down Expand Up @@ -372,6 +391,7 @@ public MergeViewerControlViewModel(IUrlAction urlAction)
/// </summary>
public virtual void ExitEditMode()
{
CurrentEditText = string.Empty;
EditingLeft = false;
EditingRight = false;
EditingText = false;
Expand Down Expand Up @@ -555,6 +575,31 @@ protected async Task CopyTextAsync(bool leftSide)
await urlAction.CopyAsync(leftSide ? LeftSide : RightSide);
}

/// <summary>
/// Deletes the lines.
/// </summary>
/// <param name="leftSide">if set to <c>true</c> [left side].</param>
protected virtual void DeleteLines(bool leftSide)
{
var selected = leftSide ? LeftSideSelected : RightSideSelected;
var source = leftSide ? LeftDiff : RightDiff;
if (selected.Count > 0 && selected?.Count() < source?.Count())
{
foreach (var item in selected)
{
source.Remove(item);
}
if (leftSide)
{
SetText(string.Join(Environment.NewLine, source.Where(p => p.Text != null).Select(p => p.Text)), RightSide);
}
else
{
SetText(LeftSide, string.Join(Environment.NewLine, source.Where(p => p.Text != null).Select(p => p.Text)));
}
}
}

/// <summary>
/// Finds the conflict.
/// </summary>
Expand Down Expand Up @@ -773,6 +818,8 @@ protected override void OnActivated(CompositeDisposable disposables)
}
}).DisposeWith(disposables);

var okEnabled = this.WhenAnyValue(v => v.CurrentEditText, v => !string.IsNullOrWhiteSpace(v));

OKCommand = ReactiveCommand.Create(() =>
{
if (EditingLeft)
Expand All @@ -786,7 +833,7 @@ protected override void OnActivated(CompositeDisposable disposables)
SetText(LeftSide, merged);
}
ExitEditMode();
}).DisposeWith(disposables);
}, okEnabled).DisposeWith(disposables);

CancelCommand = ReactiveCommand.Create(() =>
{
Expand All @@ -798,6 +845,14 @@ protected override void OnActivated(CompositeDisposable disposables)
EditingLeft = leftSide;
EditingRight = !leftSide;
EditingText = true;
if (leftSide)
{
CurrentEditText = LeftSide;
}
else
{
CurrentEditText = RightSide;
}
LeftDocument = new TextDocument(LeftSide);
RightDocument = new TextDocument(RightSide);
}).DisposeWith(disposables);
Expand All @@ -817,6 +872,11 @@ protected override void OnActivated(CompositeDisposable disposables)
FindConflict(leftSide, false);
}).DisposeWith(disposables);

DeleteTextCommand = ReactiveCommand.Create((bool leftSide) =>
{
DeleteLines(leftSide);
}).DisposeWith(disposables);

base.OnActivated(disposables);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 03-20-2020
//
// Last Modified By : Mario
// Last Modified On : 04-16-2020
// Last Modified On : 04-17-2020
// ***********************************************************************
// <copyright file="MergeViewerControlView.xaml.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -324,6 +324,9 @@ void setEditMode()
}
}
}
lines = editor.Text.SplitOnNewLine().ToList();
string text = string.Join(Environment.NewLine, lines);
ViewModel.CurrentEditText = text;
};
}

Expand Down Expand Up @@ -426,6 +429,12 @@ private List<MenuItem> GetEditableMenuItems(bool leftSide)
Header = "-"
},
new MenuItem()
{
Header = ViewModel.DeleteText,
Command = ViewModel.DeleteTextCommand,
CommandParameter = leftSide
},
new MenuItem()
{
Header = ViewModel.MoveUp,
Command = ViewModel.MoveUpCommand,
Expand Down

0 comments on commit 46ef41d

Please sign in to comment.