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

Reload document on application:openFile: #576

Open
sveinbjornt opened this issue Mar 1, 2016 · 14 comments
Open

Reload document on application:openFile: #576

sveinbjornt opened this issue Mar 1, 2016 · 14 comments

Comments

@sveinbjornt
Copy link

I often use MacDown to view Markdown documents that I edit using XCode, by selecting "Open with External Editor" from within XCode. However, the Markdown document is not reloaded when reopened with Macdown.

It would be great if Macdown reloaded the Markdown document when it receives an application:openFile: event. Just a suggestion from a casual user.

@joelwross
Copy link

+1. Running external tools to modify the file (e.g., doctoc) it would be useful if the source window would update on changes, or if there was a way to "reload" the source without opening and closing the document.

@FranklinYu
Copy link
Member

I tried these steps but didn't reproduce the issue:

  1. open foo.md with MacDown;
  2. close the window of foo.md;
  3. edit foo.md in another editor;
  4. open foo.md with MacDown, again;

I saw an updated foo.md. Did I miss anything?

@klonos
Copy link

klonos commented Feb 18, 2017

Did I miss anything?

Yep, step 2: IIUTC you should not close the document from MacDown. If the file is edited with another editor and then saved while still open in MacDown, then the document should be reloaded in MacDown (so that the changes from the other editor are loaded).

@sveinbjornt
Copy link
Author

The best logic for this is:

if unchanged document open and it is changed by another program:
    update document with changes from the other program
else if changed document open and it is changed by another program:
    ask user if he wants to overwrite his changes or keep own edits

@uranusjr
Copy link
Member

uranusjr commented Feb 18, 2017

[…] when it receives an application:openFile: event.

Would this work? I thought this is called only when you open a file. It would be the way to go if this is also called when an open document becomes active.

Note: I did try using presentedItemDidChange to detect external modification (#651), but that doesn’t work.

@sveinbjornt
Copy link
Author

I've used VDKQueue for this kind of thing in my own projects.

@FranklinYu
Copy link
Member

Then this is a duplicate of #48. How does application:openFile: help here? Will that be automatically called by the system when the file is updated?

@FranklinYu
Copy link
Member

Yes @uranusjr mentioned VDKQueue in #564 (comment).

@sveinbjornt
Copy link
Author

applicationShouldHandleReopen is what I had in mind initially:

https://developer.apple.com/reference/appkit/nsapplicationdelegate/1428638-applicationshouldhandlereopen?language=objc

But VDKQueue is the way to go. That way, the file is automatically updated without MacDown needing an apple event to trigger it.

@uranusjr
Copy link
Member

The problem about VDKQueue is I can’t find any documentation nor discussion about it. And I make sure it does not have any quirks before using it.

@sveinbjornt
Copy link
Author

I've used it in my projects for years without trouble, but YMMV.

@uranusjr
Copy link
Member

It seems like Transmission also uses it… I guess that’s good enough.

@FranklinYu
Copy link
Member

FranklinYu commented Feb 18, 2017

Note that

you'll want to modify the code to make it Arc-compliant if you use it in that environment.

according to bdkjones/VDKQueue#8. We can use the fork that fixed that; I scanned the network and this fork seems to merged everything (which also brings risks of course).

@getaaron
Copy link
Collaborator

getaaron commented Mar 9, 2017

Doesn't NSDocument handle this by calling readFromData: ofType: error:? And in this method we call [self reloadFromLoadedString].

Is there a bug in this implementation? Not sure why we need VDKQueue if NSDocument handles the file changes for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants