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 6 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 @@ -59,6 +59,7 @@ private void setSearchPane() {
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.PushToEmacs;
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,26 @@ public void onDirectoryDelete(File directory) {
};
}

// Handle mouse click event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

public void handleMouseClick(MouseEvent event, CitationsDisplay citationsDisplay) {
// Get the currently selected item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

Citation selectedItem = citationsDisplay.getSelectionModel().getSelectedItem();

// Check if the left mouse button was double-clicked
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2 && selectedItem != null) {
// Perform a jump or other actions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

String applicationName = preferences.getPushToApplicationPreferences()
.getActiveApplicationName();
PushToApplication application = PushToApplications.getApplicationByName(
applicationName,
dialogService,
preferences)
.orElse(new PushToEmacs(dialogService, preferences));
preferences.getPushToApplicationPreferences().setActiveApplicationName(application.getDisplayName());
application.publicJumpToLine(selectedItem.path(), selectedItem.line(), selectedItem.colStart());
}
}

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

Expand Down
37 changes: 37 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,40 @@ public Optional<KeyBinding> getKeyBinding() {
return Optional.of(KeyBinding.PUSH_TO_APPLICATION);
}
}

/**
* This function is to jump to a specific line due to different editor.
*
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

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

// Check if a path to the command has been specified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these kinds of comments - there are clear form the code.

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

// Execute the command
String[] command = jumpString(fileName, line, column);

try {
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.start();
} catch (IOException e) {
// Use robust logging instead of printStackTrace()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

LOGGER.error("Could not open TeXstudio at the specified location.", e);

// Show an error dialog to the user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clear from the line below - remove comment

dialogService.showErrorDialogAndWait("Error", "Could not open TeXstudio at the specified location.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use localization. Paramterize the tool using %0. See https://devdocs.jabref.org/code-howtos/localization.html for details.

}
}

protected String[] jumpString(Path fileName, int line, int column) {
koppor marked this conversation as resolved.
Show resolved Hide resolved
return new String[0];
}

public void publicJumpToLine(Path fileName, int line, int column) {
jumpToLine(fileName, line, column);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these methods for? I think, they can be deleted?

}
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 publicJumpToLine(Path fileName, int line, int column);
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ private void pushEntries() {
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
application.pushEntries(database, stateManager.getSelectedEntries(), getKeyString(stateManager.getSelectedEntries(), application.getDelimiter()));
}
// private void jump(Path fileName, int line, int column) {
// BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
// application.publicJumpToLine(database, stateManager.getSelectedEntries(), getKeyString(stateManager.getSelectedEntries(), application.getDelimiter()));
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commented-out code needed?

}
11 changes: 11 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,13 @@ public JabRefIcon getApplicationIcon() {
protected String[] getCommandLine(String keyString) {
return new String[] {commandPath, "--insert-cite", "%s%s%s".formatted(getCitePrefix(), keyString, getCiteSuffix())};
}

/**
* Method to open TeXstudio at the given line number in the specified LaTeX file.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove obsolete comment - next line states the same

@Override
public String[] jumpString(Path fileName, int line, int column) {
// Construct the TeXstudio command
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remvoe comment. It is clear from the context.

return new String[] {commandPath, "--line", Integer.toString(line), fileName.toString()};
}
}
Loading