fixed archive behaviour
This commit is contained in:
parent
b07e888bae
commit
b65f459511
@ -1199,9 +1199,7 @@ public class FilePanelTab extends JPanel {
|
||||
if (row >= 0) {
|
||||
FileItem item = (viewMode == ViewMode.BRIEF) ? tableModel.getItemFromBriefLayout(row, briefCurrentColumn) : tableModel.getItem(row);
|
||||
if (item != null && !item.isFtp()) {
|
||||
if (item.isDirectory() || (item.getFile() != null && FileOperations.canOpenAsArchive(item.getFile()))) {
|
||||
openSelectedItem();
|
||||
}
|
||||
enterSelectedArchive(item, row, viewMode == ViewMode.BRIEF ? briefCurrentColumn : 0);
|
||||
}
|
||||
}
|
||||
e.consume();
|
||||
@ -2280,6 +2278,54 @@ public class FilePanelTab extends JPanel {
|
||||
if (currentArchiveTempDir == null || currentArchiveSourceFile == null) return;
|
||||
FileOperations.rewriteArchiveFromDirectory(currentArchiveTempDir.toFile(), currentArchiveSourceFile, currentArchivePassword, callback);
|
||||
}
|
||||
|
||||
private boolean shouldEnterArchiveOnActivation(File file) {
|
||||
return FileOperations.isArchiveFile(file);
|
||||
}
|
||||
|
||||
private void enterSelectedArchive(FileItem item, int row, int column) {
|
||||
if (item == null || item.isFtp()) return;
|
||||
|
||||
if (!item.isDirectory() && FileOperations.canOpenAsArchive(item.getFile())) {
|
||||
enterArchiveItem(item, row, column);
|
||||
}
|
||||
}
|
||||
|
||||
private void enterArchiveItem(FileItem item, int row, int column) {
|
||||
ReturnNavigationState returnState = rememberReturnStateForItem(item, row, column);
|
||||
rememberArchiveReturnState(item.getFile());
|
||||
final File archiveFile = item.getFile();
|
||||
|
||||
// Extract archive asynchronously
|
||||
extractArchiveToTempAsync(archiveFile,
|
||||
temp -> {
|
||||
try {
|
||||
if (currentArchiveTempDir != null && !currentArchiveTempDir.equals(temp)) {
|
||||
// Save changes from previous archive before switching (only if modified)
|
||||
if (currentArchiveSourceFile != null && FileOperations.supportsArchiveRewrite(currentArchiveSourceFile)) {
|
||||
if (hasArchiveBeenModified()) {
|
||||
try {
|
||||
FileOperations.rewriteArchiveFromDirectory(currentArchiveTempDir.toFile(), currentArchiveSourceFile, currentArchivePassword, null);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Warning: Failed to save changes to archive " + currentArchiveSourceFile.getName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
deleteTempDirRecursively(currentArchiveTempDir);
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
currentArchiveTempDir = temp;
|
||||
currentArchiveSourceFile = archiveFile;
|
||||
archiveExtractTime = System.currentTimeMillis(); // Track extraction time
|
||||
loadDirectory(temp.toFile());
|
||||
},
|
||||
error -> {
|
||||
discardReturnState(returnState);
|
||||
clearArchiveReturnState();
|
||||
JOptionPane.showMessageDialog(FilePanelTab.this, error, "Archive Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void openSelectedItem() {
|
||||
int selectedRow = fileTable.getSelectedRow();
|
||||
@ -2305,40 +2351,8 @@ public class FilePanelTab extends JPanel {
|
||||
|
||||
if (item.getName().equals("..")) {
|
||||
navigateUp();
|
||||
} else if (FileOperations.canOpenAsArchive(item.getFile())) {
|
||||
ReturnNavigationState returnState = rememberReturnStateForItem(item, selectedRow, viewMode == ViewMode.BRIEF ? briefCurrentColumn : 0);
|
||||
rememberArchiveReturnState(item.getFile());
|
||||
final File archiveFile = item.getFile();
|
||||
|
||||
// Extract archive asynchronously
|
||||
extractArchiveToTempAsync(archiveFile,
|
||||
temp -> {
|
||||
try {
|
||||
if (currentArchiveTempDir != null && !currentArchiveTempDir.equals(temp)) {
|
||||
// Save changes from previous archive before switching (only if modified)
|
||||
if (currentArchiveSourceFile != null && FileOperations.supportsArchiveRewrite(currentArchiveSourceFile)) {
|
||||
if (hasArchiveBeenModified()) {
|
||||
try {
|
||||
FileOperations.rewriteArchiveFromDirectory(currentArchiveTempDir.toFile(), currentArchiveSourceFile, currentArchivePassword, null);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Warning: Failed to save changes to archive " + currentArchiveSourceFile.getName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
deleteTempDirRecursively(currentArchiveTempDir);
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
currentArchiveTempDir = temp;
|
||||
currentArchiveSourceFile = archiveFile;
|
||||
archiveExtractTime = System.currentTimeMillis(); // Track extraction time
|
||||
loadDirectory(temp.toFile());
|
||||
},
|
||||
error -> {
|
||||
discardReturnState(returnState);
|
||||
clearArchiveReturnState();
|
||||
JOptionPane.showMessageDialog(FilePanelTab.this, error, "Archive Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
);
|
||||
} else if (shouldEnterArchiveOnActivation(item.getFile())) {
|
||||
enterArchiveItem(item, selectedRow, viewMode == ViewMode.BRIEF ? briefCurrentColumn : 0);
|
||||
} else if (item.isDirectory()) {
|
||||
rememberReturnStateForItem(item, selectedRow, viewMode == ViewMode.BRIEF ? briefCurrentColumn : 0);
|
||||
loadDirectory(item.getFile());
|
||||
@ -2855,7 +2869,7 @@ public class FilePanelTab extends JPanel {
|
||||
|
||||
if (item.getName().equals("..")) {
|
||||
navigateUp();
|
||||
} else if (FileOperations.canOpenAsArchive(item.getFile())) {
|
||||
} else if (shouldEnterArchiveOnActivation(item.getFile())) {
|
||||
ReturnNavigationState returnState = rememberReturnStateForItem(item, row, viewMode == ViewMode.BRIEF ? col : 0);
|
||||
rememberArchiveReturnState(item.getFile());
|
||||
final File archiveFile = item.getFile();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user