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

Double click on citation opens LaTeX editor #12044

Merged
merged 35 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
066bbab
First version of the double click issue
u7465990 Oct 20, 2024
b0821bf
First version to use double click to open TeXstudio
u7465990 Oct 20, 2024
87b5750
Merge branch 'main' into feature-latex-editor#11996
u7465990 Oct 20, 2024
84fdf95
change the click count to two
u7465990 Oct 20, 2024
7f95c8b
I set the GitHub page for the test
u7465990 Oct 20, 2024
a41d5dd
Replace exec() with ProcessBuilder and printStackTrace() with LOGGER
u7465990 Oct 20, 2024
677c604
change some useless functions
u7465990 Oct 22, 2024
52158ee
I solve the csl-styles submodel problem
u7465990 Oct 22, 2024
eef355e
Solve the avvrv.jabref.org conflict
u7465990 Oct 22, 2024
998659c
The double click function works fine for the emacs external program
u7465990 Oct 23, 2024
1c22c56
The double click function works fine for the TeXworks external program
u7465990 Oct 23, 2024
0a655ff
Merge remote-tracking branch 'origin/main' into feature-latex-editor#…
koppor Oct 23, 2024
8294e73
I changed the required code. I also delete some useless comment. I ma…
u7465990 Oct 23, 2024
45c6777
finished texWorks and delete some comments
u7465990 Oct 23, 2024
ac62f2d
delete some comments
u7465990 Oct 23, 2024
0731c36
solve conflicts
u7465990 Oct 23, 2024
1387c4b
Merge branch 'feature-latex-editor#11996' of https://github.com/u7465…
u7465990 Oct 23, 2024
6bf9f30
solve untrack files
u7465990 Oct 23, 2024
1372e2a
I make Sublime Text works for this feature
u7465990 Oct 23, 2024
7944ee3
I make WinEdt works for this feature
u7465990 Oct 23, 2024
85fa67e
delete some command and change jumpString to jumpToLineCommandlineArg…
u7465990 Oct 23, 2024
d120835
Fix csl-styles
u7465990 Oct 23, 2024
6afaaef
Fix abbrv.jabref.org submodules
u7465990 Oct 23, 2024
b7b2312
I make Vim works for this feature
u7465990 Oct 23, 2024
b5040b3
I rewrite jumpToLine for TexShop. But I don't hava a Mac OS machine. …
u7465990 Oct 23, 2024
5d0bbfb
Delete the JumpToLine in TeXshop and a comment line in TeXstudio
u7465990 Oct 23, 2024
ac33148
Fix submodules (and wrong file)
koppor Oct 23, 2024
2d456a5
Merge remote-tracking branch 'origin/main' into feature-latex-editor#…
koppor Oct 23, 2024
f48766b
Fix empty lines
koppor Oct 23, 2024
b6bbf06
Default should be TeXstudio
koppor Oct 23, 2024
e117247
Remvoe "Integer.format" (and add test)
koppor Oct 23, 2024
551b074
Fix PushToVim
koppor Oct 23, 2024
61395fa
Cleanup PushToLyx
koppor Oct 23, 2024
aeedbb4
Refactor PushToVim
koppor Oct 23, 2024
3b9fbac
Add CHANGELOG.md entry
koppor Oct 23, 2024
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 @@ -56,8 +56,10 @@ public LatexCitationsTab(BibDatabaseContext databaseContext,

private void setSearchPane() {
progressIndicator.setMaxSize(100, 100);

citationsDisplay.basePathProperty().bindBidirectional(viewModel.directoryProperty());
citationsDisplay.setItems(viewModel.getCitationList());
citationsDisplay.setOnMouseClicked(event -> viewModel.handleMouseClick(event, citationsDisplay));

RowConstraints mainRow = new RowConstraints();
mainRow.setVgrow(Priority.ALWAYS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.push.PushToApplication;
import org.jabref.gui.push.PushToApplications;
import org.jabref.gui.push.PushToTeXstudio;
import org.jabref.gui.texparser.CitationsDisplay;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -154,6 +160,22 @@ public void onDirectoryDelete(File directory) {
};
}

public void handleMouseClick(MouseEvent event, CitationsDisplay citationsDisplay) {
Citation selectedItem = citationsDisplay.getSelectionModel().getSelectedItem();

if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2 && selectedItem != null) {
String applicationName = preferences.getPushToApplicationPreferences()
.getActiveApplicationName();
PushToApplication application = PushToApplications.getApplicationByName(
applicationName,
dialogService,
preferences)
.orElse(new PushToTeXstudio(dialogService, preferences));
preferences.getPushToApplicationPreferences().setActiveApplicationName(application.getDisplayName());
application.jumpToLine(selectedItem.path(), selectedItem.line(), selectedItem.colStart());
}
}

public void bindToEntry(BibEntry entry) {
checkAndUpdateDirectory();

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/jabref/gui/push/AbstractPushToApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.push;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -181,4 +182,28 @@ public Optional<KeyBinding> getKeyBinding() {
return Optional.of(KeyBinding.PUSH_TO_APPLICATION);
}
}

public void jumpToLine(Path fileName, int line, int column) {
commandPath = preferences.getPushToApplicationPreferences().getCommandPaths().get(this.getDisplayName());

if (StringUtil.isNullOrEmpty(commandPath)) {
notDefined = true;
return;
}

String[] command = jumpToLineCommandlineArguments(fileName, line, column);
ProcessBuilder processBuilder = new ProcessBuilder();
try {
processBuilder.command(command);
processBuilder.start();
} catch (IOException excep) {
LOGGER.warn("Error: Could not call executable '{}'", commandPath, excep);
couldNotCall = true;
}
}

protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
LOGGER.error("Not yet implemented");
return new String[0];
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToApplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.push;

import java.nio.file.Path;
import java.util.List;

import org.jabref.gui.actions.Action;
Expand Down Expand Up @@ -56,4 +57,6 @@ public interface PushToApplication {
PushToApplicationSettings getSettings(PushToApplication application, PushToApplicationPreferences pushToApplicationPreferences);

String getDelimiter();

void jumpToLine(Path fileName, int line, int column);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static String getKeyString(List<BibEntry> entries, String delimiter) {
for (BibEntry bes : entries) {
citeKey = bes.getCitationKey();
if (citeKey.isEmpty() || citeKey.get().isEmpty()) {
// Should never occur, because we made sure that all entries have keys
koppor marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.warn("Should never occur, because we made sure that all entries have keys");
continue;
}
if (first) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToEmacs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -147,4 +148,9 @@ protected String getCommandName() {
public PushToApplicationSettings getSettings(PushToApplication application, PushToApplicationPreferences preferences) {
return new PushToEmacsSettings(application, dialogService, this.preferences.getFilePreferences(), preferences);
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "+%s".formatted(line), fileName.toString()};
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToSublimeText.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ protected String[] getCommandLine(String keyString) {
return new String[] {"sh", "-c", "\"" + commandPath + "\"" + " --command 'insert {\"characters\": \"" + citeCommand + keyString + getCiteSuffix() + "\"}'"};
}
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "%s:%s:%s".formatted(fileName.toString(), line, column)};
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToTeXstudio.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.push;

import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -27,4 +29,9 @@ public JabRefIcon getApplicationIcon() {
protected String[] getCommandLine(String keyString) {
return new String[] {commandPath, "--insert-cite", "%s%s%s".formatted(getCitePrefix(), keyString, getCiteSuffix())};
}

@Override
public String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "--line", Integer.toString(line), fileName.toString()};
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToTeXworks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.push;

import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -33,4 +35,10 @@ public JabRefIcon getApplicationIcon() {
protected String[] getCommandLine(String keyString) {
return new String[] {commandPath, "--insert-text", "%s%s%s".formatted(getCitePrefix(), keyString, getCiteSuffix())};
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
// No command known to jump to a specific line
return new String[] {commandPath, fileName.toString()};
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToTexmaker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.push;

import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -30,4 +32,9 @@ public JabRefIcon getApplicationIcon() {
protected String[] getCommandLine(String keyString) {
return new String[] {commandPath, "-insert", getCitePrefix() + keyString + getCiteSuffix()};
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "-line", Integer.toString(line), fileName.toString()};
}
}
72 changes: 64 additions & 8 deletions src/main/java/org/jabref/gui/push/PushToVim.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

Expand All @@ -10,6 +11,7 @@
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.os.OS;
import org.jabref.logic.util.HeadlessExecutorService;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -44,14 +46,7 @@ public PushToApplicationSettings getSettings(PushToApplication application, Push

@Override
public void pushEntries(BibDatabaseContext database, List<BibEntry> entries, String keys) {
couldNotPush = false;
couldNotCall = false;
notDefined = false;

commandPath = preferences.getPushToApplicationPreferences().getCommandPaths().get(this.getDisplayName());

if ((commandPath == null) || commandPath.trim().isEmpty()) {
notDefined = true;
if (!determineCommandPath()) {
return;
}

Expand Down Expand Up @@ -105,4 +100,65 @@ public void onOperationCompleted() {
super.onOperationCompleted();
}
}

@Override
public void jumpToLine(Path fileName, int line, int column) {
if (!determineCommandPath()) {
return;
}

ProcessBuilder processBuilder = new ProcessBuilder();
try {
String[] command = jumpToLineCommandlineArguments(fileName, line, column);
if (OS.WINDOWS) {
processBuilder.command("cmd",
"/c",
"start",
"",
"\"%s\"".formatted(command[0]),
"\"%s\"".formatted(command[1]),
"\"%s\"".formatted(command[2]),
"\"+normal %s|\"".formatted(Integer.toString(column)));
} else if (OS.LINUX) {
processBuilder.command("gnome-terminal",
"--",
command[0],
command[1],
command[2],
command[3]);
} else if (OS.OS_X) {
processBuilder.command("open",
"-a",
"Terminal",
"--args",
command[0],
command[1],
command[2],
command[3]);
}
processBuilder.start();
} catch (IOException e) {
LOGGER.warn("Problem pushing to Vim.", e);
couldNotCall = true;
}
}

private boolean determineCommandPath() {
couldNotPush = false;
couldNotCall = false;
notDefined = false;

commandPath = preferences.getPushToApplicationPreferences().getCommandPaths().get(this.getDisplayName());

if ((commandPath == null) || commandPath.trim().isEmpty()) {
notDefined = true;
return false;
}
return true;
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "+%s".formatted(line), fileName.toString(), "+\"normal %s|\"".formatted(column)};
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/jabref/gui/push/PushToWinEdt.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.push;

import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
Expand Down Expand Up @@ -28,4 +30,9 @@ protected String[] getCommandLine(String keyString) {
return new String[] {commandPath,
"\"[InsText('" + getCitePrefix() + keyString.replace("'", "''") + getCiteSuffix() + "');]\""};
}

@Override
protected String[] jumpToLineCommandlineArguments(Path fileName, int line, int column) {
return new String[] {commandPath, "\"[Open(|%s|);SelLine(%s,%s);]\"".formatted(fileName.toString(), line, column)};
}
}
30 changes: 30 additions & 0 deletions src/test/java/org/jabref/gui/push/PushToWinEdtTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jabref.gui.push;

import java.nio.file.Path;

import org.jabref.gui.DialogService;
import org.jabref.gui.preferences.GuiPreferences;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;

class PushToWinEdtTest {

private DialogService dialogService;
private GuiPreferences preferences;

@BeforeEach
void setup() {
dialogService = mock(DialogService.class, Answers.RETURNS_DEEP_STUBS);
preferences = mock(GuiPreferences.class);
}

@Test
void jumpToLineCommandlineArguments() {
assertNotNull(new PushToWinEdt(dialogService, preferences).jumpToLineCommandlineArguments(Path.of("test.tex"), 1, 5));
}
}
Loading