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

Extract native functions to OS package #965

Merged
merged 6 commits into from
Mar 15, 2016
Merged

Extract native functions to OS package #965

merged 6 commits into from
Mar 15, 2016

Conversation

stefan-kolb
Copy link
Member

  • Change in CHANGELOG.md described?
  • Changes in pull request outlined? (What, why, ...)
  • Tests created for changes?
  • Tests green?


public static void openFile(String link) throws IOException {
ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("ps");
String viewer = type == null ? Globals.prefs.get(JabRefPreferences.PSVIEWER) : type.getOpenWith();
Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment, this cannot be moved to the logic package, as it uses preferences @tobiasdiez . Maybe we should pass this setting as well as to this method/class?

@Siedlerchr
Copy link
Member

A next step would be to integrate the code for the OpenOffice Path detection, too:
https://github.com/JabRef/jabref/blob/master/src/main/java/net/sf/jabref/openoffice/AutoDetectPaths.java

@stefan-kolb
Copy link
Member Author

@Siedlerchr Good point, but this requires more work as the logic is mixed with file chooser dialogs etc.

@stefan-kolb stefan-kolb added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 15, 2016
@simonharrer
Copy link
Contributor

👍

@tobiasdiez
Copy link
Member

Nice improvement!

Does it make sense to use the state pattern here? That is, the JabrefDesktop class has an internal OS object which is initialized to the correct OS in the constructor and most of the methods just pass through to the OS class. Has the advantage, that the if(OS.Windows) ... elseif(OS.Linux) disappear.

@stefan-kolb
Copy link
Member Author

@tobiasdiez Definitely worth a shot! 👍

@stefan-kolb
Copy link
Member Author

The problem is that we need to have an implementation for each of the OS then + a OS-independent implementation. This is not the case which makes it hard to implement that correctly now, as far as I can see.

@tobiasdiez
Copy link
Member

Mhh, but isn't the JabRefDesktop the OS-independent version (at least from the outside it doesn't matter what OS is used) and the newly created classes are the OS-dependent version?

My idea was to write

if(OS.Windows)
   NativeDesktop os = new Windows();
if(OS.Linux)
   NativeDesktop os = new Linux();

in the constructor of JabRefDesktop (where os is a private field) and then call for example os.openFile(link, "ps"); instead of the three if clauses.

@stefan-kolb
Copy link
Member Author

Yeah, I got your idea, but there need to be a lot of things touched to make this work consistently. Let me give it a try...

@stefan-kolb
Copy link
Member Author

I'll for example get problems with this method:

    public static void openFolderAndSelectFile(String fileLink) throws IOException {
        if (OS.WINDOWS) {
            WINDOWS.openFolderAndSelectFile(fileLink);
        } else if (OS.LINUX) {
            LINUX.openFolderAndSelectFile(fileLink);
        } else {
            File f = new File(fileLink);
            Desktop.getDesktop().open(f.getParentFile());
        }
    }

As openFolderAndSelect is not implemented for OSX yet.

        if(NATIVE_DESKTOP.isPresent()) {
            NATIVE_DESKTOP.get().openFolderAndSelectFile(fileLink);
        } else {
            File f = new File(fileLink);
            Desktop.getDesktop().open(f.getParentFile());
        }

@tobiasdiez
Copy link
Member

Ah ok. If it is two much work, then just leave it as it is right now. I think it is already a big improvement over the older code.

@stefan-kolb
Copy link
Member Author

Ok, I tried to unify this stuff as much as possible. Might introduce some new behavior that need to be fixed later on. Still got problems with the preferences that are used via ExternalFileType that force me to keep the code inside the gui package and JabRefDesktop for now.

simonharrer added a commit that referenced this pull request Mar 15, 2016
Extract native functions to OS package
@simonharrer simonharrer merged commit 54929f7 into master Mar 15, 2016
@simonharrer simonharrer deleted the native branch March 15, 2016 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants