添加移动功能
This commit is contained in:
parent
c5fc9ac223
commit
c82a22bf31
@ -38,7 +38,7 @@ public partial class MainTreePanel : Tree
|
||||
SetColumnTitlesVisible(true);
|
||||
|
||||
SetColumnTitle(0, "文件名");
|
||||
SetColumnCustomMinimumWidth(0, 800);
|
||||
SetColumnCustomMinimumWidth(0, 400);
|
||||
SetColumnExpand(0, true);
|
||||
|
||||
MultiSelected += OnMultiSelected;
|
||||
|
||||
@ -6,4 +6,6 @@ namespace Learn.Config;
|
||||
public class AppConfig : IConfigItem
|
||||
{
|
||||
public string ScanPath { get; set; } = "";
|
||||
|
||||
public string TargetPath { get; set; } = "";
|
||||
}
|
||||
28
FileMover.cs
28
FileMover.cs
@ -6,7 +6,7 @@ using Learn.Parsers;
|
||||
|
||||
namespace Learn;
|
||||
|
||||
public class FileMover(string targetPath)
|
||||
public class FileMover(string targetPath, bool preview)
|
||||
{
|
||||
private readonly HashSet<TreeNode> _visited = new ();
|
||||
|
||||
@ -77,8 +77,8 @@ public class FileMover(string targetPath)
|
||||
|
||||
var filename = string.Join(" ", string.Join(" ", filenameParts), string.Join("", metaParts.Select(part => $"[{part}]")));
|
||||
filename += Path.GetExtension(path);
|
||||
var filePath = string.Join("/", targetPath, relativePath, filename);
|
||||
node.Info.Info["TargetPath"] = filePath;
|
||||
var target = string.Join("/", targetPath, relativePath, filename);
|
||||
MoveIt(node, target);
|
||||
}
|
||||
|
||||
private void MoveExtra(TreeNode node)
|
||||
@ -87,8 +87,26 @@ public class FileMover(string targetPath)
|
||||
|
||||
var path = node.Info.MainInfo[ItemFields.MainKey_Path];
|
||||
var name = Path.GetFileName(path);
|
||||
var target = string.Join("/", targetPath, relativePath, name);
|
||||
node.Info.Info["TargetPath"] = target;
|
||||
var target = string.Join("/", targetPath, relativePath, "Extra", name);
|
||||
MoveIt(node, target);
|
||||
}
|
||||
|
||||
private void MoveIt(TreeNode node, string targetPath)
|
||||
{
|
||||
node.Info.Info["TargetPath"] = targetPath;
|
||||
if (preview) return;
|
||||
var path = node.Info.MainInfo[ItemFields.MainKey_Path];
|
||||
if (File.Exists(targetPath)) return;
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
|
||||
Directory.Move(path, targetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
|
||||
File.Move(path, targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void DoMove(TreeNode node)
|
||||
|
||||
14
Main.cs
14
Main.cs
@ -22,6 +22,7 @@ public partial class Main : Node
|
||||
[Export] private Button _doParseButton;
|
||||
[Export] private Button _doTMDBParseButton;
|
||||
[Export] private Button _doMoveButton;
|
||||
[Export] private Button _startMoveButton;
|
||||
[Export] private Button _saveButton;
|
||||
[Export] private Button _resetButton;
|
||||
[Export] private Button _loadButton;
|
||||
@ -83,7 +84,8 @@ public partial class Main : Node
|
||||
_doParseButton.Pressed += DoParse;
|
||||
_doTMDBParseButton.Pressed += DoTMDBParse;
|
||||
_saveButton.Pressed += DoSave;
|
||||
_doMoveButton.Pressed += DoMove;
|
||||
_doMoveButton.Pressed += () => DoMove(true);
|
||||
_startMoveButton.Pressed += () => DoMove(false);
|
||||
_resetButton.Pressed += DoReset;
|
||||
_loadButton.Pressed += LoadData;
|
||||
_reloadConfigButton.Pressed += ReloadConfig;
|
||||
@ -216,9 +218,9 @@ public partial class Main : Node
|
||||
|
||||
private const string DataPath = "data.json";
|
||||
|
||||
private void DoMove()
|
||||
private void DoMove(bool preview)
|
||||
{
|
||||
var mover = new FileMover("");
|
||||
var mover = new FileMover(_configs.Get<AppConfig>().TargetPath, preview);
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
@ -226,6 +228,12 @@ public partial class Main : Node
|
||||
}
|
||||
|
||||
_mainTreePanel.UpdateColumns();
|
||||
DoSave();
|
||||
|
||||
if (!preview)
|
||||
{
|
||||
ScanDir();
|
||||
}
|
||||
}
|
||||
|
||||
private void DoSave()
|
||||
|
||||
@ -17,13 +17,14 @@ grow_vertical = 2
|
||||
[node name="FileDirDialog" type="FileDialog" parent="."]
|
||||
script = ExtResource("1_d2g23")
|
||||
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_doMoveButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_doMoveButton", "_startMoveButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
script = ExtResource("2_0727o")
|
||||
_dirSelector = NodePath("../FileDirDialog")
|
||||
_openDirButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/ScanDir")
|
||||
_doParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoParse")
|
||||
_doTMDBParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoTMDBParse")
|
||||
_doMoveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoMove")
|
||||
_startMoveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/StartMove")
|
||||
_saveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Save")
|
||||
_resetButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Reset")
|
||||
_loadButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Load")
|
||||
@ -61,6 +62,8 @@ layout_mode = 2
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 7.0
|
||||
theme_override_font_sizes/font_size = 8
|
||||
theme_override_font_sizes/title_button_font_size = 12
|
||||
allow_search = false
|
||||
hide_root = true
|
||||
select_mode = 2
|
||||
@ -114,6 +117,10 @@ layout_mode = 2
|
||||
text = "整理选中部分
|
||||
"
|
||||
|
||||
[node name="StartMove" type="Button" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作"]
|
||||
layout_mode = 2
|
||||
text = "开始移动"
|
||||
|
||||
[node name="保存操作" type="VBoxContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
@ -19,6 +19,8 @@ config/icon="res://icon.svg"
|
||||
|
||||
window/size/viewport_width=1600
|
||||
window/size/viewport_height=900
|
||||
window/stretch/mode="canvas_items"
|
||||
window/stretch/aspect="expand"
|
||||
|
||||
[dotnet]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user