Skip to content

Commit

Permalink
Fix setting of title (and remove obsolete comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Mar 15, 2020
1 parent 0628f11 commit 4b0b662
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 48 deletions.
18 changes: 5 additions & 13 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class BasePanel extends StackPane {
private final FileAnnotationCache annotationCache;

private final JabRefFrame frame;
// The undo manager.
private final CountingUndoManager undoManager;

private final SidePaneManager sidePaneManager;
Expand All @@ -80,13 +79,10 @@ public class BasePanel extends StackPane {
private final DialogService dialogService;
private MainTable mainTable;
private BasePanelPreferences preferences;
// To contain instantiated entry editors. This is to save time
// As most enums, this must not be null
private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING;
private SplitPane splitPane;
private DatabaseChangePane changePane;
private boolean saving;
// AutoCompleter used in the search bar
private PersonNameSuggestionProvider searchAutoCompleter;
private boolean baseChanged;
private boolean nonUndoableChange;
Expand Down Expand Up @@ -539,11 +535,12 @@ public void updateEntryEditorIfShowing() {
}
}

/**
* Put an asterisk behind the filename to indicate the database has changed.
*/
public void markBaseChanged() {
baseChanged = true;
// Put an asterisk behind the filename to indicate the database has changed.
frame.setWindowTitle();
DefaultTaskExecutor.runInJavaFXThread(frame::updateAllTabTitles);
frame.refreshTitleAndTabs();
}

public void markNonUndoableBaseChanged() {
Expand All @@ -558,13 +555,8 @@ public synchronized void markChangedOrUnChanged() {
}
} else if (baseChanged && !nonUndoableChange) {
baseChanged = false;
if (getBibDatabaseContext().getDatabaseFile().isPresent()) {
frame.setTabTitle(this, getTabTitle(), getBibDatabaseContext().getDatabaseFile().get().getAbsolutePath());
} else {
frame.setTabTitle(this, Localization.lang("untitled"), null);
}
}
frame.setWindowTitle();
frame.refreshTitleAndTabs();
}

public BibDatabase getDatabase() {
Expand Down
46 changes: 14 additions & 32 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
*/
public class JabRefFrame extends BorderPane {

// Frame titles.
public static final String FRAME_TITLE = "JabRef";

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefFrame.class);
Expand All @@ -164,7 +163,6 @@ public class JabRefFrame extends BorderPane {
private final CountingUndoManager undoManager;
private final PushToApplicationsManager pushToApplicationsManager;
private final DialogService dialogService;
private final JabRefExecutorService executorService;
private SidePaneManager sidePaneManager;
private TabPane tabbedPane;
private SidePane sidePane;
Expand All @@ -176,7 +174,6 @@ public JabRefFrame(Stage mainStage) {
this.pushToApplicationsManager = new PushToApplicationsManager(dialogService, stateManager);
this.undoManager = Globals.undoManager;
this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction());
this.executorService = JabRefExecutorService.INSTANCE;
}

private static BasePanel getBasePanel(Tab tab) {
Expand Down Expand Up @@ -281,39 +278,26 @@ private Void showTrackingNotification() {

public void refreshTitleAndTabs() {
DefaultTaskExecutor.runInJavaFXThread(() -> {

setWindowTitle();
updateAllTabTitles();
setWindowTitle();
});
}

/**
* Sets the title of the main window.
*
* Relies on the result of updateAllTabTitles().
*/
public void setWindowTitle() {
private void setWindowTitle() {
BasePanel panel = getCurrentBasePanel();

// no database open
if (panel == null) {
//setTitle(FRAME_TITLE);
mainStage.setTitle(FRAME_TITLE);
return;
}

String mode = panel.getBibDatabaseContext().getMode().getFormattedName();
String modeInfo = String.format(" (%s)", Localization.lang("%0 mode", mode));
boolean isAutosaveEnabled = Globals.prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE);

if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.LOCAL) {
String changeFlag = panel.isModified() && !isAutosaveEnabled ? "*" : "";
String databaseFile = panel.getBibDatabaseContext()
.getDatabaseFile()
.map(File::getPath)
.orElse(Localization.lang("untitled"));
//setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
//setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
// + Localization.lang("shared") + "]" + modeInfo);
}
mainStage.setTitle(tabbedPane.getSelectionModel().getSelectedItem().getText() + " \u2013 " + FRAME_TITLE);
}

/**
Expand Down Expand Up @@ -961,57 +945,56 @@ private List<String> collectDatabaseFilePaths() {
dbPaths.add("");
}
} catch (IOException ex) {
LOGGER.error("Invalid database file path: " + ex.getMessage());
LOGGER.error("Invalid database file path", ex);
}
}
return dbPaths;
}

private List<String> getUniquePathParts() {
List<String> dbPaths = collectDatabaseFilePaths();

return FileUtil.uniquePathSubstrings(dbPaths);
}

public void updateAllTabTitles() {
private void updateAllTabTitles() {
List<String> paths = getUniquePathParts();
for (int i = 0; i < getBasePanelCount(); i++) {
String uniqPath = paths.get(i);
Optional<File> file = getBasePanelAt(i).getBibDatabaseContext().getDatabaseFile();

String newTitle;

if (file.isPresent()) {
if (!uniqPath.equals(file.get().getName()) && uniqPath.contains(File.separator)) {
// remove filename
uniqPath = uniqPath.substring(0, uniqPath.lastIndexOf(File.separator));
tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle() + " \u2014 " + uniqPath);
newTitle = getBasePanelAt(i).getTabTitle() + " \u2013 " + uniqPath;
} else {
// set original filename (again)
tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle());
newTitle = getBasePanelAt(i).getTabTitle();
}
} else {
tabbedPane.getTabs().get(i).setText(getBasePanelAt(i).getTabTitle());
newTitle = getBasePanelAt(i).getTabTitle();
}
tabbedPane.getTabs().get(i).setText(newTitle);
tabbedPane.getTabs().get(i).setTooltip(new Tooltip(file.map(File::getAbsolutePath).orElse(null)));
}
}

public void addTab(BasePanel basePanel, boolean raisePanel) {
// add tab
Tab newTab = new Tab(basePanel.getTabTitle(), basePanel);
tabbedPane.getTabs().add(newTab);
newTab.setOnCloseRequest(event -> {
closeTab((BasePanel) newTab.getContent());
event.consume();
});

// update all tab titles
updateAllTabTitles();

if (raisePanel) {
tabbedPane.getSelectionModel().select(newTab);
}

// Register undo/redo listener
basePanel.getUndoManager().registerListener(new UndoRedoEventManager());

BibDatabaseContext context = basePanel.getBibDatabaseContext();
Expand All @@ -1023,7 +1006,6 @@ public void addTab(BasePanel basePanel, boolean raisePanel) {

BackupManager.start(context, Globals.entryTypesManager, prefs);

// Track opening
trackOpenNewDatabase(basePanel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ private boolean doSave() {
// Reset title of tab
frame.setTabTitle(panel, panel.getTabTitle(),
panel.getBibDatabaseContext().getDatabasePath().get().toAbsolutePath().toString());
frame.setWindowTitle();
frame.updateAllTabTitles();
frame.refreshTitleAndTabs();
}
return success;
} catch (SaveException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String format(String value) {

// Remove pages prefix
String cleanValue = value.replace("pp.", "").replace("p.", "");
// remove unwanted literals incl. whitespace
// remove unwanted literals including en dash, em dash, and whitespace
cleanValue = cleanValue.replaceAll("\u2013|\u2014", "-").replaceAll(REJECT_LITERALS, "");
// try to find pages pattern
Matcher matcher = PAGES_DETECT_PATTERN.matcher(cleanValue);
Expand Down

0 comments on commit 4b0b662

Please sign in to comment.