Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements readonly #219

Merged
merged 28 commits into from
Oct 4, 2022
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f91945
Fixes conflict with PropertiesManager renaming
gtache Feb 12, 2020
693213f
Merge branch 'master' of github.com:pcorless/icepdf
gtache Feb 17, 2020
db0b33f
Merge branch 'master' of github.com:pcorless/icepdf
gtache Feb 28, 2020
a4b0f97
Merge branch 'master' of github.com:pcorless/icepdf
gtache May 12, 2020
f3f99cd
Merge branch 'master' of github.com:pcorless/icepdf
gtache May 14, 2020
ef55851
Merge branch 'master' of github.com:pcorless/icepdf
gtache Jul 8, 2020
ac12aaa
Merge branch 'master' of github.com:pcorless/icepdf
gtache Aug 17, 2020
8b28b29
Merge branch 'master' of github.com:pcorless/icepdf
gtache Aug 21, 2020
2bcaafc
Merge branch 'master' of github.com:pcorless/icepdf
gtache Sep 8, 2020
35cc9b2
Merge branch 'master' of github.com:pcorless/icepdf
gtache Sep 22, 2020
40581e1
Merge branch 'master' of github.com:pcorless/icepdf
gtache Sep 24, 2020
ff7226a
Merge branch 'master' of github.com:pcorless/icepdf
gtache Jan 27, 2021
5710f1f
Merge branch 'master' of github.com:pcorless/icepdf
gtache Mar 25, 2021
96ae8be
Merge branch 'master' of github.com:pcorless/icepdf
gtache Mar 29, 2021
d7dee59
Merge branch 'master' of github.com:pcorless/icepdf
gtache Mar 31, 2021
984725b
Merge branch 'master' of github.com:pcorless/icepdf
gtache Apr 1, 2021
f315bae
Merge branch 'master' of github.com:pcorless/icepdf
gtache Apr 16, 2021
f03025e
Merge branch 'master' of github.com:pcorless/icepdf
gtache Apr 27, 2021
4e642ca
Merge branch 'master' of github.com:pcorless/icepdf
gtache Apr 30, 2021
088951f
Merge branch 'master' of github.com:pcorless/icepdf
gtache Sep 13, 2021
c7bb958
Merge branch 'master' of github.com:pcorless/icepdf
gtache Sep 21, 2021
dd315fd
Merge branch 'master' of github.com:pcorless/icepdf
gtache Oct 28, 2021
b61f98e
Merge branch 'master' of github.com:pcorless/icepdf
gtache Dec 13, 2021
767fff6
Merge branch 'master' of github.com:pcorless/icepdf
gtache Jan 27, 2022
0ddba0f
Merge branch 'master' of github.com:pcorless/icepdf
gtache Mar 1, 2022
44beec7
GH-218 Adds readonly flag
gtache Apr 19, 2022
ab6939b
Merge branch 'master' into readonly
pcorless Oct 4, 2022
912f3eb
fix conflict mistake.
pcorless Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public class SwingController extends ComponentAdapter
USE_JFILECHOOSER = Defs.booleanProperty("org.icepdf.ri.viewer.jfilechooser", false);
}

private static final boolean IS_READONLY = Defs.booleanProperty("org.icepdf.ri.viewer.readonly", false);

public static final int CURSOR_OPEN_HAND = 1;
public static final int CURSOR_CLOSE_HAND = 2;
public static final int CURSOR_ZOOM_IN = 3;
Expand Down Expand Up @@ -1597,8 +1599,8 @@ protected void reflectStateInComponents() {

// menu items.
setEnabled(closeMenuItem, opened);
setEnabled(saveFileMenuItem, opened);
setEnabled(saveAsFileMenuItem, opened);
setEnabled(saveFileMenuItem, opened && !IS_READONLY);
setEnabled(saveAsFileMenuItem, opened && !IS_READONLY);
setEnabled(sendMailMenuItem, opened);
setEnabled(exportTextMenuItem, opened && canExtract && !pdfCollection);
setEnabled(propertiesMenuItem, opened);
Expand Down Expand Up @@ -1657,7 +1659,7 @@ protected void reflectStateInComponents() {
setEnabled(searchPreviousMenuItem, opened && searchPanel != null && !pdfCollection);
setEnabled(goToPageMenuItem, opened && nPages > 1 && !pdfCollection);

setEnabled(saveFileButton, opened);
setEnabled(saveFileButton, opened && !IS_READONLY);
setEnabled(printButton, opened && canPrint && !pdfCollection);
setEnabled(searchButton, opened && searchPanel != null && !pdfCollection);
setEnabled(showHideUtilityPaneButton, opened && utilityTabbedPane != null);
Expand Down Expand Up @@ -1689,32 +1691,32 @@ protected void reflectStateInComponents() {
setEnabled(zoomDynamicToolButton, opened && !pdfCollection);
setEnabled(textSelectToolButton, opened && canExtract && !pdfCollection);
setEnabled(selectToolButton, opened && canModify && !pdfCollection);
setEnabled(highlightAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(strikeOutAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(underlineAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(lineAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(linkAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(lineArrowAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(squareAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(circleAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(inkAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(freeTextAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(textAnnotationToolButton, opened && canModify && !pdfCollection);
setEnabled(highlightAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(strikeOutAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(underlineAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(lineAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(linkAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(lineArrowAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(squareAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(circleAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(inkAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(freeTextAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(textAnnotationToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(annotationSummaryButton, opened && canModify && !pdfCollection);
setEnabled(annotationPreviewMenuItem, opened && canModify && !pdfCollection);
setEnabled(annotationEditingModeButton, opened && !pdfCollection);
setEnabled(linkAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(highlightAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(strikeOutAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(underlineAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(lineAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(lineArrowAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(squareAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(circleAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(inkAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(freeTextAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(annotationPrivacyComboBox, opened && !pdfCollection);
setEnabled(textAnnotationPropertiesToolButton, opened && canModify && !pdfCollection);
setEnabled(annotationEditingModeButton, opened && !pdfCollection && !IS_READONLY);
setEnabled(linkAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(highlightAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(strikeOutAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(underlineAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(lineAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(lineArrowAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(squareAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(circleAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(inkAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(freeTextAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(annotationPrivacyComboBox, opened && !pdfCollection && !IS_READONLY);
setEnabled(textAnnotationPropertiesToolButton, opened && canModify && !pdfCollection && !IS_READONLY);
setEnabled(formHighlightButton, opened && !pdfCollection && hasForms());
setEnabled(quickSearchToolBar, opened && !pdfCollection);
setEnabled(facingPageViewContinuousButton, opened && !pdfCollection);
Expand Down Expand Up @@ -3459,6 +3461,7 @@ public void dispose() {
* when the window is closed.
*/
public void saveFile() {
if (IS_READONLY) return;
if (document.getStateManager().isChange() &&
saveFilePath != null &&
!saveFilePath.isEmpty()) {
Expand Down Expand Up @@ -3491,43 +3494,45 @@ public void saveFile() {
*/
public void saveFileAs() {

String originalFileName = getOriginalFileName();
String newFileName = originalFileName == null || originalFileName.isEmpty() ? null : generateNewSaveName(originalFileName);
if (!IS_READONLY) {
String originalFileName = getOriginalFileName();
String newFileName = originalFileName == null || originalFileName.isEmpty() ? null : generateNewSaveName(originalFileName);

// Create and display a file saving dialog
if (!USE_JFILECHOOSER) {
final FileDialog fileDialog = new FileDialog(getViewerFrame());
fileDialog.setTitle(messageBundle.getString("viewer.dialog.saveAs.title"));
fileDialog.setMultipleMode(false);
fileDialog.setMode(FileDialog.SAVE);
fileDialog.setFilenameFilter((file, s) -> s.endsWith(FileExtensionUtils.pdf));
if (ViewModel.getDefaultFile() != null) {
fileDialog.setDirectory(ViewModel.getDefaultFile().getParentFile().getAbsolutePath());
}
if (newFileName != null) {
fileDialog.setFile(newFileName);
}
// show the dialog
fileDialog.setVisible(true);
final String filePath = fileDialog.getFile();
final String dirPath = fileDialog.getDirectory();
if (filePath != null && dirPath != null) {
saveFileChecks(originalFileName, new File(dirPath + filePath));
}
} else {
final JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(messageBundle.getString("viewer.dialog.saveAs.title"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.addChoosableFileFilter(FileExtensionUtils.getPDFFileFilter());
if (ViewModel.getDefaultFile() != null) {
fileChooser.setCurrentDirectory(ViewModel.getDefaultFile());
}
if (newFileName != null) {
fileChooser.setSelectedFile(new File(newFileName));
}
// show the dialog
if (fileChooser.showSaveDialog(viewer) == JFileChooser.APPROVE_OPTION) {
saveFileChecks(originalFileName, fileChooser.getSelectedFile());
// Create and display a file saving dialog
if (!USE_JFILECHOOSER) {
final FileDialog fileDialog = new FileDialog(getViewerFrame());
fileDialog.setTitle(messageBundle.getString("viewer.dialog.saveAs.title"));
fileDialog.setMultipleMode(false);
fileDialog.setMode(FileDialog.SAVE);
fileDialog.setFilenameFilter((file, s) -> s.endsWith(FileExtensionUtils.pdf));
if (ViewModel.getDefaultFile() != null) {
fileDialog.setDirectory(ViewModel.getDefaultFile().getParentFile().getAbsolutePath());
}
if (newFileName != null) {
fileDialog.setFile(newFileName);
}
// show the dialog
fileDialog.setVisible(true);
final String filePath = fileDialog.getFile();
final String dirPath = fileDialog.getDirectory();
if (filePath != null && dirPath != null) {
saveFileChecks(originalFileName, new File(dirPath + filePath));
}
} else {
final JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(messageBundle.getString("viewer.dialog.saveAs.title"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.addChoosableFileFilter(FileExtensionUtils.getPDFFileFilter());
if (ViewModel.getDefaultFile() != null) {
fileChooser.setCurrentDirectory(ViewModel.getDefaultFile());
}
if (newFileName != null) {
fileChooser.setSelectedFile(new File(newFileName));
}
// show the dialog
if (fileChooser.showSaveDialog(viewer) == JFileChooser.APPROVE_OPTION) {
saveFileChecks(originalFileName, fileChooser.getSelectedFile());
}
}
}
}
Expand Down Expand Up @@ -3723,7 +3728,7 @@ public void exportText() {
public boolean saveChangesDialog() {
// check if document changes have been made, if so ask the user if they
// want to save the changes.
if (document != null) {
if (document != null && !IS_READONLY) {
boolean documentChanges = document.getStateManager().hasChangedSinceLastSnapshot();
if (documentChanges) {
MessageFormat formatter = new MessageFormat(
Expand Down Expand Up @@ -5818,4 +5823,4 @@ private void callOnFilteredAnnotations(final AnnotationFilter filter, final Cons
}
}
}
}
}