From 993ca4fe0f801bea8127cfaf4c050d467cfd5326 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Wed, 17 Nov 2021 19:29:03 +0100 Subject: [PATCH] fix: save document before creating backup --- oxt/description.xml | 2 +- .../docsettings/document/ODFDocument.java | 18 +++++++++++++----- .../litvinovg/docsettings/gui/BackupPanel.java | 12 ++++++++---- .../localizations/docsettings.properties | 2 +- .../localizations/docsettings_ru.properties | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/oxt/description.xml b/oxt/description.xml index 7ffe423..90ee3de 100644 --- a/oxt/description.xml +++ b/oxt/description.xml @@ -1,7 +1,7 @@ - + Управление настройками документов diff --git a/src/main/java/pro/litvinovg/docsettings/document/ODFDocument.java b/src/main/java/pro/litvinovg/docsettings/document/ODFDocument.java index 4494a42..1586426 100644 --- a/src/main/java/pro/litvinovg/docsettings/document/ODFDocument.java +++ b/src/main/java/pro/litvinovg/docsettings/document/ODFDocument.java @@ -163,9 +163,9 @@ public class ODFDocument { } public void restoreSettings(Settings settings) { - closeDocument(); + close(); restoreFrom(settings); - reOpenDoc(); + reopen(); } public XPropertyContainer getUserDefinedProps(){ @@ -284,7 +284,7 @@ public class ODFDocument { } - public void reOpenDoc(){ + public void reopen(){ try { XComponent doc = loader.loadComponentFromURL(url, "_default", 0, new PropertyValue[0]); } catch (Exception e) { @@ -293,7 +293,15 @@ public class ODFDocument { ; } - public void closeDocument() { + public void save() { + if (context != null) { + executedispatch("Save", new PropertyValue[0]); + } else { + logger.debug("Can't save document. No context."); + } + } + + public void close() { if (context != null) { executedispatch("CloseDoc", new PropertyValue[0]); } else { @@ -301,7 +309,7 @@ public class ODFDocument { } } - public void reloadDocument() { + public void reload() { if (context != null) { executedispatch("Reload", new PropertyValue[0]); } else { diff --git a/src/main/java/pro/litvinovg/docsettings/gui/BackupPanel.java b/src/main/java/pro/litvinovg/docsettings/gui/BackupPanel.java index 89d4107..db48207 100644 --- a/src/main/java/pro/litvinovg/docsettings/gui/BackupPanel.java +++ b/src/main/java/pro/litvinovg/docsettings/gui/BackupPanel.java @@ -67,6 +67,7 @@ public class BackupPanel extends JPanel { lst_backups.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); JLabel lb_backups = new JLabel(Localizer.get("backup_panel_description")); + lb_backups.setHorizontalAlignment(SwingConstants.CENTER); btn_delete = new JButton(Localizer.get("delete_backup_button")); btn_create = new JButton(Localizer.get("create_backup_button")); @@ -82,18 +83,18 @@ public class BackupPanel extends JPanel { groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(43) - .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(lb_backups, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(groupLayout.createSequentialGroup() - .addComponent(lst_backups, GroupLayout.PREFERRED_SIZE, 354, GroupLayout.PREFERRED_SIZE) - .addGap(26) + .addComponent(lst_backups, GroupLayout.PREFERRED_SIZE, 247, GroupLayout.PREFERRED_SIZE) + .addGap(53) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addComponent(cb_stick_latest_backup, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_close, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_delete, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE) .addComponent(btn_create, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_restore, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) - .addContainerGap(288, Short.MAX_VALUE)) + .addGap(39)) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) @@ -133,8 +134,10 @@ public class BackupPanel extends JPanel { if (document == null) { return; } + document.save(); backups.create(document.getCurrentSettings()); document.writeBackups(backups); + document.save(); populateList(); } }); @@ -152,6 +155,7 @@ public class BackupPanel extends JPanel { String selected = (String) lst_backups.getSelectedValue(); backups.removeByDateTimeLabel(selected); document.writeBackups(backups); + document.save(); populateList(); } }); diff --git a/src/main/java/pro/litvinovg/docsettings/localizations/docsettings.properties b/src/main/java/pro/litvinovg/docsettings/localizations/docsettings.properties index c548a78..5e1d4b0 100644 --- a/src/main/java/pro/litvinovg/docsettings/localizations/docsettings.properties +++ b/src/main/java/pro/litvinovg/docsettings/localizations/docsettings.properties @@ -6,7 +6,7 @@ settings_tab_name = Settings backups_tab_name = Backups backup_panel_description = Manage document settings backups no_timestamp_found_error = No backup dates found -stick_latest_backup_cb_label = Block settings +stick_latest_backup_cb_label = Freeze settings in all documents no_backup_selected = Select backup and try again error_document_not_found = Document not found. error_document_is_not_saved = Document is not saved. Save document before proceeding. diff --git a/src/main/java/pro/litvinovg/docsettings/localizations/docsettings_ru.properties b/src/main/java/pro/litvinovg/docsettings/localizations/docsettings_ru.properties index 9561147..ae2ed4a 100644 --- a/src/main/java/pro/litvinovg/docsettings/localizations/docsettings_ru.properties +++ b/src/main/java/pro/litvinovg/docsettings/localizations/docsettings_ru.properties @@ -6,7 +6,7 @@ settings_tab_name = Настройки backups_tab_name = Резервные копии backup_panel_description = Управление резервными копиями настроек документов no_timestamp_found_error = Не найдено дат резервных копий -stick_latest_backup_cb_label = Заблокировать изменение настроек +stick_latest_backup_cb_label = Замораживать настройки всех документов no_backup_selected = Выберите резервную копию и попробуйте снова error_document_not_found = Ошибка. Документ не найден. error_document_is_not_saved = Документ не сохранен. Сохраните документ и попробуйте снова.