Skip to content

Commit 5df3e7a

Browse files
committed
Update duplicate media directory dialog text
1 parent 6a02f42 commit 5df3e7a

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

src/main/java/listfix/view/GUIScreen.java

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,78 +1904,74 @@ private void _addMediaDirButtonActionPerformed()
19041904

19051905
private void addMediaFolder(File mediaFolderToAdd)
19061906
{
1907-
try
1907+
1908+
UNCFile mediaDir = new UNCFile(mediaFolderToAdd);
1909+
if (getApplicationConfig().getAlwaysUseUNCPaths())
19081910
{
1909-
UNCFile mediaDir = new UNCFile(mediaFolderToAdd);
1910-
if (getApplicationConfig().getAlwaysUseUNCPaths())
1911+
if (mediaDir.onNetworkDrive())
19111912
{
1912-
if (mediaDir.onNetworkDrive())
1913-
{
1914-
mediaDir = new UNCFile(mediaDir.getUNCPath());
1915-
}
1913+
mediaDir = new UNCFile(mediaDir.getUNCPath());
19161914
}
1917-
final String dir = mediaDir.getPath();
1915+
}
1916+
final String dir = mediaDir.getPath();
19181917

1919-
// first let's see if this is a subdirectory of any of the media directories already in the list, and error out if so...
1920-
if (ArrayFunctions.containsStringPrefixingAnotherString(_listFixController.getMediaLibrary().getMediaDirectories(), dir, !ListFixController.FILE_SYSTEM_IS_CASE_SENSITIVE))
1921-
{
1922-
JOptionPane.showMessageDialog(this, new JTransparentTextArea("The directory you attempted to add is a subdirectory of one already in your media library, no change was made."),
1923-
"Reminder", JOptionPane.INFORMATION_MESSAGE);
1924-
return;
1925-
}
1926-
else
1918+
// first let's see if this is a subdirectory of any of the media directories already in the list, and error out if so...
1919+
if (ArrayFunctions.containsStringPrefixingAnotherString(_listFixController.getMediaLibrary().getMediaDirectories(), dir, !ListFixController.FILE_SYSTEM_IS_CASE_SENSITIVE))
1920+
{
1921+
JOptionPane.showMessageDialog(this, new JTransparentTextArea("The directory you attempted to add is a subdirectory of one already in your media library, no change was made."),
1922+
"Notification", JOptionPane.INFORMATION_MESSAGE);
1923+
return;
1924+
}
1925+
else
1926+
{
1927+
// Now check if any of the media directories is a subdirectory of the one we're adding and remove the media directory if so.
1928+
int removedFolders = 0;
1929+
for (String dirToCheck : new ArrayList<>(_listFixController.getMediaLibrary().getMediaDirectories()))
19271930
{
1928-
// Now check if any of the media directories is a subdirectory of the one we're adding and remove the media directory if so.
1929-
int matchCount = 0;
1930-
for (String dirToCheck : _listFixController.getMediaLibrary().getMediaDirectories())
1931+
if (dirToCheck.startsWith(dir))
19311932
{
1932-
if (dirToCheck.startsWith(dir))
1933-
{
1934-
// Only showing the message the first time we find this condition...
1935-
if (matchCount == 0)
1936-
{
1937-
JOptionPane.showMessageDialog(this,
1938-
new JTransparentTextArea("One or more of your existing media directories is a subdirectory of the directory you just added. These directories will be removed from your list automatically."),
1939-
"Reminder", JOptionPane.INFORMATION_MESSAGE);
1940-
}
1941-
removeMediaDir(dirToCheck);
1942-
matchCount++;
1943-
}
1933+
// Only showing the message the first time we find this condition...
1934+
removeMediaDir(dirToCheck);
1935+
removedFolders++;
19441936
}
19451937
}
1946-
1947-
ProgressWorker<Void, Void> worker = new ProgressWorker<>()
1938+
if (removedFolders > 0)
19481939
{
1949-
@Override
1950-
protected Void doInBackground()
1951-
{
1952-
MediaLibraryOperator operator = new MediaLibraryOperator(this);
1953-
operator.addDirectory(dir);
1954-
return null;
1955-
}
1956-
};
1957-
ProgressDialog pd = new ProgressDialog(this, true, worker, "Updating Media Library...", true, true);
1958-
pd.setVisible(true);
1959-
1960-
try
1961-
{
1962-
worker.get();
1963-
}
1964-
catch (InterruptedException | CancellationException ex)
1965-
{
1966-
_logger.debug("Cancelled");
1940+
String message = String.format("Removed %d duplicated media directories", removedFolders);
1941+
_logger.info(message);
1942+
JOptionPane.showMessageDialog(this,
1943+
new JTransparentTextArea(String.format(message)),
1944+
"Notification", JOptionPane.INFORMATION_MESSAGE);
19671945
}
1968-
catch (ExecutionException ex)
1946+
}
1947+
1948+
ProgressWorker<Void, Void> worker = new ProgressWorker<>()
1949+
{
1950+
@Override
1951+
protected Void doInBackground()
19691952
{
1970-
_logger.error(ex);
1953+
MediaLibraryOperator operator = new MediaLibraryOperator(this);
1954+
operator.addDirectory(dir);
1955+
return null;
19711956
}
1972-
_lstMediaLibraryDirs.setListData(new Vector<>(_listFixController.getMediaLibrary().getMediaDirectories()));
1957+
};
1958+
1959+
ProgressDialog pd = new ProgressDialog(this, true, worker, "Updating Media Library...", true, true);
1960+
pd.setVisible(true);
1961+
1962+
try
1963+
{
1964+
worker.get();
1965+
}
1966+
catch (InterruptedException | CancellationException ex)
1967+
{
1968+
_logger.debug("Cancelled");
19731969
}
1974-
catch (HeadlessException e)
1970+
catch (ExecutionException ex)
19751971
{
1976-
JOptionPane.showMessageDialog(this, new JTransparentTextArea("An error has occurred, media directory could not be added."));
1977-
_logger.error("Error adding media directory", e);
1972+
_logger.error(ex);
19781973
}
1974+
_lstMediaLibraryDirs.setListData(new Vector<>(_listFixController.getMediaLibrary().getMediaDirectories()));
19791975
updateMediaDirButtons();
19801976
}
19811977

0 commit comments

Comments
 (0)