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

File Attachment Feature #419

Closed
tiagogala opened this Issue Dec 15, 2016 · 25 comments

Comments

Projects
None yet
5 participants
@tiagogala

tiagogala commented Dec 15, 2016

I think it would be very useful to have a feature that allows the user to attach a regular file to a note.
It could possibly work in a similar fashion to the way we currently insert pictures - by copying the file to the "media" folder or something similar. The file would then be accessible using a text link (same as when we enter a regular http link) or for some subset of files we could have a small icon or preview of the file (ex.: for pdf documents it might be useful to have a small preview of the first page, for excel a generic icon would be enough).

@pbek pbek added the enhancement label Dec 15, 2016

@pbek

This comment has been minimized.

Owner

pbek commented Dec 15, 2016

Thank you for your suggestion.
If this will be (ever) implemented, than surely not before #266 is resolved.
I guess a preview will not be possible, because that would need additional tools on every platform, same goes for mime-type icons...

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Dec 22, 2016

I just had some insight on subject.

I think it won't be hard to implement image-like drag'n'drop for non-images, including the copy to media routine. Arguably there should be an option to paste path to original file without coping it, but images doesn't have it, and nobody asks.

It's the icon/thumbnail that is tricky, and that is because the app has to carry it's own set of icons and thumbnailer for it to work on all platforms. But this part can be outsourced to a scripting engine with a file drag'n'drop hook. Maybe a general insert link hook.

If there is a hook that gives a file path, I could write an in-app script with a GNU/Linux shell commands that would:

  1. Copy that file to "attachments" directory;
  2. Use installed thumbnailers like imagemagic to make thumbnails for some file types;
  3. Get system icons as a thumbnails for other types;
  4. Insert a link with a thumbnail at cursor position with existing function.

Someone else could make scripts for other platforms.

Such script can be made even now with a custom action button, but I'd also have to make a GUI for file selection. I think drag'n'drop is much better than this.

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

@Maboroshy what do you mean by hook that gives a file path? This scripting function: http://docs.qownnotes.org/en/develop/scripting/README.html#showing-an-open-file-dialog?

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

Links like [original file name](file://attachments/qownnotes-attachment-d93Amsf3Asd3.txt) already work.

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

I've not decided yet if I rather put attachments also in the media folder, instead of a new attachments folder... Any suggestions, @Maboroshy, @msbentley, @tiagogala, @tinwasp?
But I think we should stay with simple text links that can keep the original file name (and are linking to the generated attachment file). Some generic icon would be rather annoying in the preview or an exported PDF...

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

But maybe a new folder would be better so we don't get into troubles with the dialog to delete orphaned images. And we can then also import an image as attachment (that then doesn't get a preview).

@msbentley

This comment has been minimized.

msbentley commented May 29, 2017

From my side I'd be more than happy with a simply text link to the attachment - no icons or previews needed. A new folder is also fine with me.

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented May 29, 2017

@Maboroshy what do you mean by hook that gives a file path?

I mostly feed files to the apps by drag'n'drop from file manager. So by hook I meant the scripting function that would run when user drops a file to the app windows and returns file's full path and other metadata OS gives the app.

For now the app process only images drag'n'drop, so the new function could be useful for other files types, that are currently ignored by it.

There's no standard for attachments in markdown, so the outsourcing attachments to scripting engine is the way of moving from "my way is better" discussion. "Media" or "attachments" folder, in-text links or first line links, everything can be a script setting. Also it's the way to outsource complex and possibly OS dependant attachment handling as icon handling and thumbnailers.

The bad thing is that scripts still can't edit note text. That means that any script for attachment handling needs some dependency that will handle direct file access for it.

Simple links are chops my imagination by they are maybe more understandable for most users.

As for icons, I use notes for storing some bookmarks, and I have a shell script that adds a website's favicon before every link, a small 16x16 one. My media/favicon directory currently store 122 of them. I like how it looks, and finding the site I need is faster with them.

I currently have "attachments" directory inside "media" directory, but I don't think it's a good practice. Seperate directory would be better. Also I think both "media" and "attachments" should be hidden, so ".media" and ".attachments" for me. Personally I'm all for customization, including media dir name and path.

Dead links handling can be easily run for any directory configuration with just a few of variables. But I see dead links handling as an external task. I have some saved web-pages as notes, so I use sub-directories for storing lot of images, that current dead links handling doesn't parse. So I've had shell script that does that for a long time. Maybe I can make a in-app script for that, but, again, with a dependency to handle files.

Also about leaving original names. There should be a duplicate check. I currently simply add absolute file modification time to the name if that name is already exists, but I really should get to hash comparing instead to save some disk space.

Now that's a long post... 😎

Oh, and I'm already thinking about parsing notes for attachments and using "label" thing to show them all in one place. Just need to make sure label's html can handle working local file links. And maybe some icons too.

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

We would need a script that has to work on all platforms... I guess that's possible but not an easy thing to do...
I don't have any concept on how a script should edit a note... What should the scripting engine being able to do?

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented May 29, 2017

That's quite complex. For now I see:

The good:

  1. Replace note text with the content of a variable - that goes for putting text in, deleting parts of text, regex replacements... All that can be handled by embedded functions of QML;
  2. Rename note file.

The bad:

  1. Get cursor position in text as in string;
  2. Set cursor position the same way;
  3. Get the beginning, the end and the content of text selection.

The ugly:

  1. Raw file handling: create, rename, copy, move, delete, hash etc.;
  2. Inotify handling: process externally added files, like a web page saved by browser;
  3. Custom syntax highlighting.

So adding simple attachment link to text goes as:

  1. Get dropped file path;
  2. Copy file to "attachments" dir;
  3. Get note text and cursor position;
  4. Add attached file link at cursor position and replace note text.

The frightening "move paragraph" goes as:

  1. Get note text to array with new line as IFS storing positions of each new line;
  2. Get cursor position;
  3. Check what element of array it is in;
  4. Reorder array;
  5. Replace note text with array content;
  6. Move cursor to the same position in moved paragraph.

That way most of current edit menu items can be in-app scripts.

Having "the bad" part I can do it all externally in Python.

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

Thank you for your comprehensive list. Well, I guess I'm open for pull requests. :)

@pbek

This comment has been minimized.

Owner

pbek commented May 29, 2017

@Maboroshy, you really need to brush up your C++ and Qt skills to work on the scripting engine and all your great ideas! 😄

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented May 29, 2017

Currently I only have time to develop ideas you've implemented long time ago.
Maybe next year. 2016 was a year of learning shell, 2017 is about Python, maybe 2018 will be about C++.

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

Don't think about it as C++, mainly think about it as Qt. :)

@pbek pbek added this to the 17.05.14 milestone May 30, 2017

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

17.05.14

  • you can now use the shortcut Ctrl + + E to
    insert a file attachment into the current note
    • the file will be copied to an attachments folder in the current note
      folder (note subfolders don't have their own attachments folder) and
      a text link will be created in the note
    • the new attachments folder will be ignored in the note subfolder tree
    • you can also drag and drop files into the note, they will be inserted as
      attachment if they are not an image or a note file
    • a space character will be added in front of the attachment link if
      there was no space or new line in front of the current cursor position
@michael-rowe

This comment has been minimized.

michael-rowe commented May 30, 2017

Earlier today I started a project that I wanted to use Qownnotes for but needed the ability to attach files to notes. I popped in here to see if you'd implemented that since last I checked. You're doing amazing work :-) Thank you.

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

You will get a new release today, @michael-rowe. I just want to finish the attachment support for the Evernote import. ;)

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

There now is a new release, could you please test it and report if it works for you?

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented May 30, 2017

Tested new release. New menu item, drag'n'drop, opening links, everything works.

The only thing worth improvement is that links are always inserted to the end of the note, that is the same for media. Maybe it should be inserted at the cursor position.

Great that another long time issue about small but important feature is resolved now.

@michael-rowe

This comment has been minimized.

michael-rowe commented May 30, 2017

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

@Maboroshy, but they are inserted at the cursor position, like media files. Only if the cursor is in the first line are they inserted at the end of the note (like also for media files). Do you see an other behavior?

@michael-rowe

This comment has been minimized.

michael-rowe commented May 30, 2017

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

Yes, I just tested it on the release again too. For me it works with manual insert and with drag and drop. @Maboroshy do you have something different?

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented May 30, 2017

No different. It was a first line thing. I usually don't use note headlines, so first line behaviour was a surprise.

Close it up! 👍

@pbek

This comment has been minimized.

Owner

pbek commented May 30, 2017

ok ;)

@pbek pbek closed this May 30, 2017

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