Search in sources :

Example 1 with AutosaveManager

use of org.jabref.logic.autosaveandbackup.AutosaveManager in project jabref by JabRef.

the class JabRefFrame method addTab.

public void addTab(BasePanel basePanel, boolean raisePanel) {
    // add tab
    tabbedPane.add(basePanel.getTabTitle(), basePanel);
    // update all tab titles
    updateAllTabTitles();
    if (raisePanel) {
        tabbedPane.setSelectedComponent(basePanel);
    }
    // Register undo/redo listener
    basePanel.getUndoManager().registerListener(new UndoRedoEventManager());
    BibDatabaseContext context = basePanel.getBibDatabaseContext();
    if (readyForAutosave(context)) {
        AutosaveManager autosaver = AutosaveManager.start(context);
        autosaver.registerListener(new AutosaveUIManager(basePanel));
    }
    BackupManager.start(context);
    // Track opening
    trackOpenNewDatabase(basePanel);
}
Also used : BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) AutosaveManager(org.jabref.logic.autosaveandbackup.AutosaveManager) AutosaveUIManager(org.jabref.gui.autosaveandbackup.AutosaveUIManager)

Example 2 with AutosaveManager

use of org.jabref.logic.autosaveandbackup.AutosaveManager in project jabref by JabRef.

the class SaveDatabaseAction method saveAs.

/**
     * Run the "Save as" operation. This method offloads the actual save operation to a background thread, but
     * still runs synchronously using Spin (the method returns only after completing the operation).
     */
public void saveAs(File file) throws Exception {
    BibDatabaseContext context = panel.getBibDatabaseContext();
    if (context.getLocation() == DatabaseLocation.SHARED) {
        // Save all properties dependent on the ID. This makes it possible to restore them.
        DBMSConnectionProperties properties = context.getDBMSSynchronizer().getDBProcessor().getDBMSConnectionProperties();
        new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()).putAllDBMSConnectionProperties(properties);
    }
    context.setDatabaseFile(file);
    if (file.getParent() != null) {
        Globals.prefs.put(JabRefPreferences.WORKING_DIRECTORY, file.getParent());
    }
    runCommand();
    // If the operation failed, revert the file field and return:
    if (!success) {
        return;
    }
    try {
        panel.setFileMonitorHandle(Globals.getFileUpdateMonitor().addUpdateListener(panel, context.getDatabaseFile().orElse(null)));
    } catch (IOException ex) {
        LOGGER.error("Problem registering file change notifications", ex);
    }
    if (readyForAutosave(context)) {
        AutosaveManager autosaver = AutosaveManager.start(context);
        autosaver.registerListener(new AutosaveUIManager(panel));
    }
    if (readyForBackup(context)) {
        BackupManager.start(context);
    }
    context.getDatabaseFile().ifPresent(presentFile -> frame.getFileHistory().newFile(presentFile.getPath()));
    frame.updateEnabledState();
}
Also used : SharedDatabasePreferences(org.jabref.shared.prefs.SharedDatabasePreferences) IOException(java.io.IOException) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) AutosaveManager(org.jabref.logic.autosaveandbackup.AutosaveManager) DBMSConnectionProperties(org.jabref.shared.DBMSConnectionProperties) AutosaveUIManager(org.jabref.gui.autosaveandbackup.AutosaveUIManager)

Aggregations

AutosaveUIManager (org.jabref.gui.autosaveandbackup.AutosaveUIManager)2 AutosaveManager (org.jabref.logic.autosaveandbackup.AutosaveManager)2 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)2 IOException (java.io.IOException)1 DBMSConnectionProperties (org.jabref.shared.DBMSConnectionProperties)1 SharedDatabasePreferences (org.jabref.shared.prefs.SharedDatabasePreferences)1