I believe the profile manager is finally done for now, I hope.... Added regex patterns to the folder groups to have a standard way to format file names in a given group.
This commit is contained in:
+259
-95
@@ -6,6 +6,7 @@ using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@@ -17,14 +18,25 @@ namespace DataOrganizer
|
||||
private string MachineNameLabelText { get; } = "The Machine Name property determines what profile will be loaded automatically.\r\nCurrently: '{0}'.";
|
||||
private bool IsUpdating { get; set; }
|
||||
private ContextMenu FolderGroupListContextMenu { get; set; } = new ContextMenu();
|
||||
private ListViewItem SelectedItem { get; set; }
|
||||
private List<DB.Namingconvention> NamingConventions { get; }
|
||||
private Dictionary<string, DB.Profile> Profiles { get; } = new Dictionary<string, DB.Profile>();
|
||||
private Dictionary<string, DB.FolderGroup> FolderGroups { get; } = new Dictionary<string, DB.FolderGroup>();
|
||||
|
||||
public ProfileManager()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var db = new DB();
|
||||
var deleteMenuItem = new MenuItem("Delete");
|
||||
FolderGroupListContextMenu.MenuItems.Add(deleteMenuItem);
|
||||
NamingConventions = db.GetNamingConventions();
|
||||
NamingConventionComboBox.Items.Add("None");
|
||||
NamingConventionComboBox.SelectedIndex = 0;
|
||||
|
||||
foreach(var convention in NamingConventions)
|
||||
{
|
||||
NamingConventionComboBox.Items.Add(convention.Name);
|
||||
}
|
||||
|
||||
ProfilesComboBox.SelectedIndexChanged += ProfilesComboBox_SelectedIndexChanged;
|
||||
ProfileNameTextBox.TextChanged += ToggleAddOrUpdateButton;
|
||||
@@ -34,16 +46,30 @@ namespace DataOrganizer
|
||||
FolderGroupListView.MouseClick += FolderGroupListView_MouseClick;
|
||||
deleteMenuItem.Click += DeleteMenuItem_Click;
|
||||
|
||||
UpdateProfileComboBox();
|
||||
PopulateProfiles();
|
||||
SetupForNewProfile();
|
||||
}
|
||||
|
||||
private void FolderGroupListView_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if(e.Button == MouseButtons.Right)
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
SelectedItem = FolderGroupListView.GetItemAt(e.X, e.Y);
|
||||
FolderGroupListContextMenu.Show(FolderGroupListView, e.Location);
|
||||
}
|
||||
else if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
GetSelectedFolderGroup(out DB.FolderGroup folderGroup);
|
||||
FolderGroupPathTextBox.Text = folderGroup.Path;
|
||||
FolderNameTextBox.Text = folderGroup.Name;
|
||||
var index = NamingConventions.FindIndex(x => x.Id == folderGroup.PatternId);
|
||||
|
||||
if (index != -1)
|
||||
NamingConventionComboBox.SelectedIndex = index + 1;
|
||||
else
|
||||
NamingConventionComboBox.SelectedIndex = 0;
|
||||
|
||||
InsertGroupName.Text = "Update Folder Group";
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteMenuItem_Click(object sender, EventArgs e)
|
||||
@@ -55,21 +81,18 @@ namespace DataOrganizer
|
||||
if(result == DialogResult.Yes)
|
||||
{
|
||||
var db = new DB();
|
||||
var currentIndex = ProfilesComboBox.SelectedIndex;
|
||||
|
||||
db.DeleteFolderGroup((DB.FolderGroup) SelectedItem.Tag);
|
||||
GetSelectedFolderGroup(out DB.FolderGroup folderGroup);
|
||||
|
||||
UpdateProfileComboBox();
|
||||
db.DeleteFolderGroup(folderGroup);
|
||||
|
||||
ProfilesComboBox.SelectedIndex = currentIndex;
|
||||
RemoveFolderGroup(folderGroup.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FolderGroupListView.Items.Remove(FolderGroupListView.SelectedItems[0]);
|
||||
}
|
||||
|
||||
SelectedItem = null;
|
||||
}
|
||||
|
||||
private void MachineNameTextBox_TextChanged(object sender, EventArgs e)
|
||||
@@ -96,33 +119,6 @@ namespace DataOrganizer
|
||||
InsertGroupName.Enabled = false;
|
||||
}
|
||||
|
||||
private void UpdateProfileComboBox()
|
||||
{
|
||||
var db = new DB();
|
||||
|
||||
var profiles = db.GetProfiles();
|
||||
ProfilesComboBox.Items.Clear();
|
||||
ProfilesComboBox.Tag = null;
|
||||
ProfilesComboBox.Items.Add("Add New Profile");
|
||||
ProfilesComboBox.SelectedIndex = 0;
|
||||
FolderGroupListView.Items.Clear();
|
||||
|
||||
if (profiles.Count == 0)
|
||||
{
|
||||
ProfilesComboBox.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ProfilesComboBox.Enabled = true;
|
||||
|
||||
foreach (var profile in profiles)
|
||||
{
|
||||
ProfilesComboBox.Items.Add(profile.Name);
|
||||
}
|
||||
|
||||
ProfilesComboBox.Tag = profiles;
|
||||
}
|
||||
|
||||
private void AddOrUpdateProfileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var machineName = Environment.MachineName;
|
||||
@@ -136,19 +132,18 @@ namespace DataOrganizer
|
||||
if (!IsUpdating)
|
||||
{
|
||||
var folders = new List<DB.FolderGroup>();
|
||||
|
||||
//TODO: crash
|
||||
foreach(ListViewItem node in FolderGroupListView.Items)
|
||||
{
|
||||
folders.Add(new DB.FolderGroup
|
||||
{
|
||||
Name = node.SubItems[0].Text,
|
||||
Path = node.SubItems[1].Text
|
||||
});
|
||||
folders.Add(FolderGroups[node.Text]);
|
||||
}
|
||||
|
||||
db.InsertNewProfile(new DB.Profile { Name = ProfileNameTextBox.Text, DefaultNewContentFolder = NewContentLocationTextBox.Text, MachineName = machineName, FolderGroups = folders });
|
||||
var newProfile = new DB.Profile { Name = ProfileNameTextBox.Text, DefaultNewContentFolder = NewContentLocationTextBox.Text, MachineName = machineName, FolderGroups = folders };
|
||||
|
||||
UpdateProfileComboBox();
|
||||
db.InsertNewProfile(newProfile);
|
||||
|
||||
Profiles.Add(newProfile.Name, newProfile);
|
||||
ProfilesComboBox.Items.Add(newProfile.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -156,53 +151,21 @@ namespace DataOrganizer
|
||||
profile.Name = ProfileNameTextBox.Text;
|
||||
profile.DefaultNewContentFolder = NewContentLocationTextBox.Text;
|
||||
profile.MachineName = MachineNameTextBox.Text;
|
||||
|
||||
Profiles[profile.Name] = profile;
|
||||
|
||||
db.UpdateProfile(profile);
|
||||
}
|
||||
|
||||
UpdateProfileComboBox();
|
||||
SetupForNewProfile();
|
||||
}
|
||||
|
||||
private void ProfilesComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
FolderGroupListView.Items.Clear();
|
||||
|
||||
if (ProfilesComboBox.SelectedIndex == 0)
|
||||
{
|
||||
ProfileNameTextBox.Text = string.Empty;
|
||||
NewContentLocationTextBox.Text = string.Empty;
|
||||
MachineNameTextBox.Text = string.Empty;
|
||||
AddOrUpdateProfileButton.Text = "Add";
|
||||
AddOrUpdateProfileButton.Enabled = false;
|
||||
MachineNameLabel.Text = string.Format(MachineNameLabelText, Environment.MachineName);
|
||||
IsUpdating = false;
|
||||
DeleteProfileButton.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
IsUpdating = true;
|
||||
|
||||
GetCurrentProfile(out DB.Profile profile);
|
||||
|
||||
ProfileNameTextBox.Text = profile.Name;
|
||||
NewContentLocationTextBox.Text = profile.DefaultNewContentFolder;
|
||||
MachineNameTextBox.Text = profile.MachineName;
|
||||
DeleteProfileButton.Enabled = true;
|
||||
|
||||
MachineNameLabel.Text = string.Format(MachineNameLabelText, profile.MachineName);
|
||||
|
||||
AddOrUpdateProfileButton.Text = "Update";
|
||||
|
||||
if(profile.FolderGroups != null)
|
||||
{
|
||||
foreach(var group in profile.FolderGroups)
|
||||
{
|
||||
var item = new ListViewItem(group.Name);
|
||||
item.SubItems.Add(group.Path);
|
||||
item.Tag = group;
|
||||
|
||||
FolderGroupListView.Items.Add(item);
|
||||
}
|
||||
}
|
||||
SetupForNewProfile();
|
||||
else
|
||||
SetUpFormForUpdatingProfile();
|
||||
}
|
||||
|
||||
private void InsertGroupName_Click(object sender, EventArgs e)
|
||||
@@ -210,26 +173,55 @@ namespace DataOrganizer
|
||||
var dir = new DirectoryInfo(FolderGroupPathTextBox.Text);
|
||||
var groupName = dir.Name;
|
||||
|
||||
if (!FolderGroupListView.Items.ContainsKey(groupName))//!FolderGroupsTreeView.Nodes.ContainsKey(groupName))
|
||||
if (!FolderGroups.ContainsKey(groupName))
|
||||
{
|
||||
var item = new ListViewItem(groupName);
|
||||
item.SubItems.Add(FolderGroupPathTextBox.Text);
|
||||
GetCurrentNamingConvention(out DB.Namingconvention convention);
|
||||
GetCurrentProfile(out DB.Profile profile);
|
||||
var newFolder = new DB.FolderGroup { Name = groupName, Path = FolderGroupPathTextBox.Text, PatternId = convention.Id};
|
||||
|
||||
FolderGroupListView.Items.Add(item);
|
||||
FolderGroupListView.Items.Add(groupName);
|
||||
|
||||
if (IsUpdating)
|
||||
{
|
||||
var db = new DB();
|
||||
|
||||
GetCurrentProfile(out DB.Profile profile);
|
||||
var newId = db.InsertNewFolderGroup(profile, groupName, FolderGroupPathTextBox.Text, convention.Id);
|
||||
newFolder.Id = newId;
|
||||
|
||||
var newId = db.InsertNewFolderGroup(profile, groupName, FolderGroupPathTextBox.Text);
|
||||
profile.FolderGroups.Add(newFolder);
|
||||
|
||||
profile.FolderGroups.Add(new DB.FolderGroup { Name = groupName, Id = newId, Path = FolderGroupPathTextBox.Text });
|
||||
Profiles[profile.Name] = profile;
|
||||
}
|
||||
|
||||
FolderGroups.Add(newFolder.Name, newFolder);
|
||||
|
||||
FolderNameTextBox.Text = string.Empty;
|
||||
FolderGroupPathTextBox.Text = string.Empty;
|
||||
InsertGroupName.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var folderGroup = FolderGroups[groupName];//(DB.FolderGroup) FolderGroupListView.Items.Find(groupName, true)[0].Tag;
|
||||
folderGroup.Path = FolderGroupPathTextBox.Text;
|
||||
folderGroup.Name = groupName;
|
||||
GetCurrentNamingConvention(out DB.Namingconvention convention);
|
||||
folderGroup.PatternId = convention.Id;
|
||||
InsertGroupName.Text = "Insert Folder Group";
|
||||
|
||||
if (IsUpdating)
|
||||
{
|
||||
var db = new DB();
|
||||
db.UpdateFolderGroup(folderGroup);
|
||||
}
|
||||
|
||||
FolderGroups[groupName] = folderGroup;
|
||||
|
||||
NamingConventionComboBox.SelectedIndex = 0;
|
||||
FolderNameTextBox.Text = string.Empty;
|
||||
FolderGroupPathTextBox.Text = string.Empty;
|
||||
InsertGroupName.Enabled = false;
|
||||
}
|
||||
|
||||
FolderGroupPathTextBox.Text = string.Empty;
|
||||
FolderGroupPathButton.Focus();
|
||||
}
|
||||
|
||||
@@ -239,11 +231,35 @@ namespace DataOrganizer
|
||||
|
||||
if (!IsUpdating) return false;
|
||||
|
||||
profile = ((List<DB.Profile>)ProfilesComboBox.Tag)[ProfilesComboBox.SelectedIndex - 1];
|
||||
profile = Profiles[ProfilesComboBox.Text];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool GetCurrentNamingConvention(out DB.Namingconvention namingconvention)
|
||||
{
|
||||
namingconvention = new DB.Namingconvention();
|
||||
|
||||
if (NamingConventions.Count == 0 || NamingConventionComboBox.SelectedIndex == 0) return false;
|
||||
|
||||
namingconvention = NamingConventions[NamingConventionComboBox.SelectedIndex - 1];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool GetSelectedFolderGroup(out DB.FolderGroup folderGroup)
|
||||
{
|
||||
folderGroup = new DB.FolderGroup();
|
||||
|
||||
if(FolderGroupListView.SelectedItems.Count == 1)
|
||||
{
|
||||
folderGroup = FolderGroups[FolderGroupListView.SelectedItems[0].Text];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DeleteProfileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var result = MessageBox.Show("Are you sure? This will delete all file records (not files on disk), groups and any customization data set in this profile.", "Wipe Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
|
||||
@@ -255,17 +271,165 @@ namespace DataOrganizer
|
||||
|
||||
db.DeleteProfile(profile);
|
||||
|
||||
UpdateProfileComboBox();
|
||||
PopulateProfiles();
|
||||
SetupForNewProfile();
|
||||
}
|
||||
}
|
||||
|
||||
private void FolderGroupPathButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialog = new FolderBrowserDialog();
|
||||
var dialog = new FolderBrowserDialog() { Description = "Select a root folder that holds like content." };
|
||||
|
||||
if(dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
FolderGroupPathTextBox.Text = dialog.SelectedPath;
|
||||
InsertGroupName.Text = "Insert Folder Group";
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveFolderGroup(int folderId)
|
||||
{
|
||||
GetCurrentProfile(out DB.Profile profile);
|
||||
|
||||
profile.FolderGroups.RemoveAll(x => x.Id == folderId);
|
||||
|
||||
ClearFolderGroupControls();
|
||||
|
||||
foreach(var folder in profile.FolderGroups)
|
||||
{
|
||||
var item = new ListViewItem(folder.Name);
|
||||
item.Tag = folder;
|
||||
FolderGroupListView.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearForm()
|
||||
{
|
||||
ClearProfileDataControls();
|
||||
ClearFolderGroupControls();
|
||||
}
|
||||
|
||||
private void ClearFolderGroupControls()
|
||||
{
|
||||
FolderGroupListView.Items.Clear();
|
||||
NamingConventionComboBox.SelectedIndex = 0;
|
||||
FolderNameTextBox.Text = string.Empty;
|
||||
FolderGroupPathTextBox.Text = string.Empty;
|
||||
InsertGroupName.Enabled = false;
|
||||
}
|
||||
|
||||
private void ClearProfileDataControls()
|
||||
{
|
||||
ProfileNameTextBox.Text = string.Empty;
|
||||
NewContentLocationTextBox.Text = string.Empty;
|
||||
MachineNameTextBox.Text = string.Empty;
|
||||
DeleteProfileButton.Enabled = false;
|
||||
AddOrUpdateProfileButton.Enabled = false;
|
||||
AddOrUpdateProfileButton.Text = "Add";
|
||||
}
|
||||
|
||||
private void PopulateProfiles()
|
||||
{
|
||||
ProfilesComboBox.SelectedIndexChanged -= ProfilesComboBox_SelectedIndexChanged;
|
||||
|
||||
var db = new DB();
|
||||
Profiles.Clear();
|
||||
|
||||
var profiles = db.GetProfiles();
|
||||
|
||||
foreach(var profile in profiles)
|
||||
{
|
||||
Profiles.Add(profile.Name, profile);
|
||||
}
|
||||
|
||||
ProfilesComboBox.Items.Clear();
|
||||
ProfilesComboBox.Items.Add("Add New Profile");
|
||||
ProfilesComboBox.SelectedIndex = 0;
|
||||
|
||||
if (Profiles.Count == 0)
|
||||
ProfilesComboBox.Enabled = false;
|
||||
else
|
||||
{
|
||||
ProfilesComboBox.Enabled = true;
|
||||
|
||||
foreach (var profile in Profiles)
|
||||
{
|
||||
ProfilesComboBox.Items.Add(profile.Value.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ProfilesComboBox.SelectedIndexChanged += ProfilesComboBox_SelectedIndexChanged;
|
||||
}
|
||||
|
||||
private void RefreshProfileComboBox()
|
||||
{
|
||||
ProfilesComboBox.SelectedIndexChanged -= ProfilesComboBox_SelectedIndexChanged;
|
||||
|
||||
ProfilesComboBox.Items.Clear();
|
||||
ProfilesComboBox.Items.Add("Add New Profile");
|
||||
ProfilesComboBox.SelectedIndex = 0;
|
||||
|
||||
if (Profiles.Count == 0)
|
||||
ProfilesComboBox.Enabled = false;
|
||||
else
|
||||
{
|
||||
ProfilesComboBox.Enabled = true;
|
||||
|
||||
foreach (var profile in Profiles)
|
||||
{
|
||||
ProfilesComboBox.Items.Add(profile.Value.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ProfilesComboBox.SelectedIndexChanged += ProfilesComboBox_SelectedIndexChanged;
|
||||
}
|
||||
|
||||
private void SetupForNewProfile()
|
||||
{
|
||||
ClearForm();
|
||||
RefreshProfileComboBox();
|
||||
IsUpdating = false;
|
||||
FolderGroups.Clear();
|
||||
|
||||
MachineNameLabel.Text = string.Format(MachineNameLabelText, Environment.MachineName);
|
||||
AddOrUpdateProfileButton.Text = "Add";
|
||||
ProfileNameTextBox.Focus();
|
||||
}
|
||||
|
||||
private void SetUpFormForUpdatingProfile()
|
||||
{
|
||||
ClearForm();
|
||||
IsUpdating = true;
|
||||
|
||||
GetCurrentProfile(out DB.Profile profile);
|
||||
|
||||
ProfileNameTextBox.Text = profile.Name;
|
||||
NewContentLocationTextBox.Text = profile.DefaultNewContentFolder;
|
||||
MachineNameTextBox.Text = profile.MachineName;
|
||||
MachineNameLabel.Text = string.Format(MachineNameLabelText, profile.MachineName);
|
||||
FolderGroups.Clear();
|
||||
|
||||
if (profile.FolderGroups != null)
|
||||
{
|
||||
foreach (var group in profile.FolderGroups)
|
||||
{
|
||||
FolderGroupListView.Items.Add(group.Name);
|
||||
FolderGroups.Add(group.Name, group);
|
||||
}
|
||||
}
|
||||
|
||||
AddOrUpdateProfileButton.Text = "Update";
|
||||
AddOrUpdateProfileButton.Enabled = true;
|
||||
DeleteProfileButton.Enabled = true;
|
||||
}
|
||||
|
||||
private void SelectNewContentLocationButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialog = new FolderBrowserDialog() { Description = "Select the default location to look for new content." };
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
NewContentLocationTextBox.Text = dialog.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user