-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manager: Allow selecting multiple log directories
- Loading branch information
Showing
3 changed files
with
93 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace GW2Scratch.ArcdpsLogManager.Controls; | ||
|
||
public class DirectoryListControl : DynamicLayout | ||
{ | ||
private List<string> directories; | ||
|
||
public IEnumerable<string> Directories | ||
{ | ||
get => directories; | ||
set | ||
{ | ||
directories = value?.ToList() ?? new List<string>(); | ||
RecreateLayout(); | ||
} | ||
} | ||
|
||
private void RecreateLayout() | ||
{ | ||
if (directories == null) | ||
{ | ||
SuspendLayout(); | ||
Clear(); | ||
ResumeLayout(); | ||
return; | ||
} | ||
|
||
SuspendLayout(); | ||
Clear(); | ||
|
||
BeginVertical(spacing: new Size(5, 5)); | ||
{ | ||
foreach ((int i, string directory) in directories.Select((x, i) => (i, x))) | ||
{ | ||
BeginHorizontal(); | ||
Add(new TextBox { Text = directory, ReadOnly = true }, true); | ||
var removeButton = new Button { Text = "Remove" }; | ||
removeButton.Click += (_, _) => | ||
{ | ||
directories.RemoveAt(i); | ||
// This will trigger the setter which rebuilds the layout. | ||
Directories = directories; | ||
}; | ||
Add(removeButton, false); | ||
EndHorizontal(); | ||
} | ||
|
||
AddRow(ConstructAddButton()); | ||
} | ||
EndVertical(); | ||
|
||
Create(); | ||
ResumeLayout(); | ||
} | ||
|
||
private Button ConstructAddButton() | ||
{ | ||
var button = new Button { Text = "Add a log directory" }; | ||
button.Click += (_, _) => | ||
{ | ||
var dialog = new SelectFolderDialog(); | ||
if (dialog.ShowDialog(this) == DialogResult.Ok) | ||
{ | ||
if (!Directories.Contains(dialog.Directory)) | ||
{ | ||
Directories = Directories.Append(dialog.Directory); | ||
} | ||
} | ||
}; | ||
return button; | ||
} | ||
} |