mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 03:33:18 +01:00
Allow drag-n-drop in "Multiple replace" rules - thx Clarencezzh :)
Fix #7509
This commit is contained in:
parent
75d4ab98f0
commit
a54d6cec3f
@ -7,7 +7,6 @@ using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Nikse.SubtitleEdit.Logic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -215,7 +216,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
string findText = textBoxFind.Text.RemoveControlCharacters();
|
||||
var findText = textBoxFind.Text.RemoveControlCharacters();
|
||||
if (findText.Length > 0)
|
||||
{
|
||||
string searchType = ReplaceExpression.SearchTypeNormal;
|
||||
@ -887,6 +888,92 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
listViewGroups.SelectedIndexChanged += listViewGroups_SelectedIndexChanged;
|
||||
MultipleReplace_ResizeEnd(sender, null);
|
||||
listViewGroups_SelectedIndexChanged(null, null);
|
||||
|
||||
listViewRules.AllowDrop = true;
|
||||
listViewRules.DragEnter += ListViewRulesDragEnter;
|
||||
listViewRules.DragDrop += ListViewRulesDragDrop;
|
||||
listViewRules.ItemDrag += listView1_ItemDrag;
|
||||
listViewRules.DragOver += ListViewRulesOnDragOver;
|
||||
}
|
||||
|
||||
private void ListViewRulesOnDragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_privateDrag)
|
||||
{
|
||||
e.Effect = DragDropEffects.Move;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _privateDrag;
|
||||
|
||||
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
|
||||
{
|
||||
_privateDrag = true;
|
||||
DoDragDrop(e.Item, DragDropEffects.Move);
|
||||
_privateDrag = false;
|
||||
}
|
||||
|
||||
void ListViewRulesDragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_privateDrag)
|
||||
{
|
||||
e.Effect = DragDropEffects.Move;
|
||||
}
|
||||
}
|
||||
|
||||
void ListViewRulesDragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (!_privateDrag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var x = e.Data.GetData(typeof(ListViewItem));
|
||||
if (x is ListViewItem item)
|
||||
{
|
||||
var hit = listViewRules.HitTest(listViewRules.PointToClient(new Point(e.X, e.Y)));
|
||||
if (hit.Item?.Tag != null)
|
||||
{
|
||||
var items = new List<MultipleSearchAndReplaceSetting>();
|
||||
foreach (int index in listViewRules.SelectedIndices)
|
||||
{
|
||||
items.Add(_currentGroup.Rules[index]);
|
||||
}
|
||||
|
||||
foreach (var removeItem in items)
|
||||
{
|
||||
_currentGroup.Rules.Remove(removeItem);
|
||||
}
|
||||
|
||||
var insertBeforeElement = _currentGroup.Rules.FirstOrDefault(p => p == hit.Item.Tag);
|
||||
if (insertBeforeElement == null)
|
||||
{
|
||||
foreach (var i in items)
|
||||
{
|
||||
_currentGroup.Rules.Add(i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var insertIndex = _currentGroup.Rules.IndexOf(insertBeforeElement);
|
||||
foreach (var i in items)
|
||||
{
|
||||
_currentGroup.Rules.Insert(insertIndex, i);
|
||||
insertIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
listViewRules.BeginUpdate();
|
||||
listViewRules.Items.Clear();
|
||||
foreach (var rule in _currentGroup.Rules)
|
||||
{
|
||||
AddToRulesListView(rule);
|
||||
}
|
||||
listViewRules.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
_privateDrag = false;
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
|
Loading…
Reference in New Issue
Block a user