-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa1c4e5
commit b51f3ad
Showing
122 changed files
with
821 additions
and
554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.sf.jabref; | ||
|
||
import net.sf.jabref.model.database.BibDatabase; | ||
import net.sf.jabref.model.database.BibDatabaseMode; | ||
import net.sf.jabref.model.database.BibDatabaseModeDetection; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Represents everything related to a .bib file. | ||
* <p> | ||
* The entries are stored in BibDatabase, the other data in MetaData and the options relevant for this file in Defaults. | ||
*/ | ||
public class BibDatabaseContext { | ||
|
||
private final BibDatabase database; | ||
private final MetaData metaData; | ||
private final Defaults defaults; | ||
|
||
public BibDatabaseContext(Defaults defaults) { | ||
this(new BibDatabase(), defaults); | ||
} | ||
|
||
public BibDatabaseContext(BibDatabase database, Defaults defaults) { | ||
this(database, new MetaData(), defaults); | ||
} | ||
|
||
public BibDatabaseContext(BibDatabase database, MetaData metaData, Defaults defaults) { | ||
this.defaults = Objects.requireNonNull(defaults); | ||
this.database = Objects.requireNonNull(database); | ||
this.metaData = Objects.requireNonNull(metaData); | ||
|
||
this.setMode(getMode()); | ||
} | ||
|
||
public BibDatabaseContext(BibDatabase database, MetaData metaData, File file, Defaults defaults) { | ||
this(database, metaData, defaults); | ||
|
||
this.metaData.setFile(file); | ||
} | ||
|
||
public BibDatabaseMode getMode() { | ||
List<String> data = metaData.getData(MetaData.DATABASE_TYPE); | ||
if (data == null) { | ||
BibDatabaseMode inferredMode = BibDatabaseModeDetection.inferMode(database); | ||
if (defaults.mode == BibDatabaseMode.BIBLATEX || inferredMode == BibDatabaseMode.BIBLATEX) { | ||
return BibDatabaseMode.BIBLATEX; | ||
} else { | ||
return BibDatabaseMode.BIBTEX; | ||
} | ||
} | ||
return BibDatabaseMode.valueOf(data.get(0).toUpperCase()); | ||
} | ||
|
||
public void setMode(BibDatabaseMode bibDatabaseMode) { | ||
metaData.putData(MetaData.DATABASE_TYPE, Collections.singletonList(bibDatabaseMode.getFormattedName())); | ||
} | ||
|
||
/** | ||
* Get the file where this database was last saved to or loaded from, if any. | ||
* | ||
* @return The relevant File, or null if none is defined. | ||
*/ | ||
public File getDatabaseFile() { | ||
return metaData.getFile(); | ||
} | ||
|
||
public BibDatabase getDatabase() { | ||
return database; | ||
} | ||
|
||
public MetaData getMetaData() { | ||
return metaData; | ||
} | ||
|
||
public boolean isBiblatexMode() { | ||
return getMode() == BibDatabaseMode.BIBLATEX; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Why create a new BibDatabaseContext here instead of reusing panel.gitBibDatabaseContext ?