Intercept Save from "NSDocument is about to close sheet" - save

When an NSDocument is marked as having changes and the user closes it, a sheet is shown with options for Don't Save, Close and Save.
How can I intercept or disable the Save button?
I have overridden -saveDocument: and -saveDocumentAs: but these are not called when saving from this warning sheet?
I am trying to warn users that the document will be saved into a new file format (if I know the document is in an old format) and would also like to prevent saving documents in the demo version of the software.
Is there anyway to modify this path so I can show my own sheet instead?

You can intercept it by overriding NSDocument's canClose(withDelegate:shouldClose:contextInfo:). The method is called when user is going to close a document. Thus, you can create your own alert sheet there before calling super's.

Related

Editing a PDF in UIDocumentInteractionController and saving..?

I've got an 'interactive PDF' that I need to be able to edit and save in an iOS app and I'm looking at how to achieve it. It's got text boxes and radio buttons which I can interact with in the UIDocumentInteractionController preview (or QLPreviewController) but there doesn't seem to be a way to save those changes to the file that was loaded and if I share the live and edited file to my mac via AirDrop it doesn't send the changes, rather it seems just the original file.
I don't really know anything about interactive PDFs so not sure how added text would normally be saved. I've found that the 'Files' app (added in iOS 11) actually saves the edits you make, so that's basically what I want to be able to do.
At the end of the day I just need a way to be able to interact with a PDF in my app and save the changes. Do I maybe need to use a custom PDF viewer rather than trying to piggy back off the standard iOS file previewer functionality?
Looks like this library solves my problem: https://github.com/derekblair/ILPDFKit
It lets you edit a PDF, access and set individual fields and save out as a static PDF.

Processing a long running process (uploading large Excel files); Ruby on Rails 4.0

I have a create action in a controller that is in charged of uploading Excel files. Some of these Excel files take a long time to process. Once the Excel file is validated and the content of the file is saved in a table, the user is redirected to another view where they see a success flash notification.
I would like to alter this process but honest to gosh I would love some guidance or perhaps a link to something similar.
1) I am trying to make it so, once the create button is selected and the validations pass, the user is redirected elsewhere and once the file upload is completed, the user will be notified regardless on where they are in the application.
2)While an excel file is being processed, the create option is not available to any other user. (Currently, if the file is being processed, it stays in the new view and if you keep clicking on the create button, it processes the file over again prolonging the uploading process)
Thanks in advance for the help!
From my point of view you should do following steps:
1) Create a special storage for states (global place where information about file upload status is stored). I propose to use key-value storage such as redis or memcached
2) When user upload file you save it to the disk, queue background job (resque or delayed_job) and set flag file_is_processing to true
3) In your views disable button if file_is_processing flag is set.
4) In background job you validate file and if it is not valid set a flag in storage not_valid_file & remove file_is_processing flag
5) Have before action where you check this state and if file is not valid redirect user to file upload page with notice & remove not_valid_file flag.
6) If file is valid you parse file then remove file_is_processing flag & set file_is_processed
7) In before action redirect user to success page, show notice & remove file_is_processed
Seems to be easiest way for me.

Open Office save file without functions

I want to save a open office calc documents without all the functions in it to prevent that the functions calculate all the time I open it. Im using a template document where the functions are in it.
To prevent functions from calculating, go to Tools -> Cell Contents and uncheck AutoCalculate. Then save the template. When you create a document using the template, the AutoCalculate setting will be off.
To calculate functions, either press Ctrl-Shift-F9 or turn AutoCalculate back on.

Actionscript downloading a File using FileReference

I'm having trouble working on FileReference download(URL) function. I needed to automatically download the files in a particular space on my harddisk but the SAVE AS dialog always displays. can I make it automatically download in a certain place on my disk?
I'm going to assume "automatically download" means "save" here. Nope, If you use FileReference (or File in AIR), there's no way to automatically save without showing the Save As dialog box.
If you don't need to access the file outside of the app, then take a look at the SharedObject class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html. By default you can create SharedObjects of up to 100KB without needing the client's permission (see the description of getLocal()), which should be fine for more simple text or xml info - you can compress it using ByteArray if you want to save space. Any more than that and a small dialog will open asking permission. Once you've given permission however, it won't ask again.

Prepopulate file upload form in struts 2

I am working on a struts 2 web application where user can upload file through a file upload form, if the file already exists in database, a confirmation message should be displayed to overwrite the existing file or cancel the action.
On upload the database is queried for that file and if it exists the action results and set a flag in session which shows the jquery dialog box for user confirmation. I need to implement continue button in the dialog box which will set another flag to specify overwrite and call the same action again, this time the file will be uploaded. To implement this I need to prefill the file upload input box with previous request parameter before calling the upload action.
Is there any other method to implement the above requirement?
Please let me know in case any details are required.
Thanks in advance.
I assume that you dont want to upload a file if a file with same filename exists in the database. If this is the case, why dont you check for the duplicity of filenames as soon as a file is selected to upload. This can be done in two ways
load list of all the filenames along with the page and check the selected filename with this list
Use ajax to send request to server for checking for duplicate filename when a file is selected
You can use the onchange event of the file element
For security reasons, you cannot mess with the value attribute of the file element programatically, otherwise you could fill-in any file from the user's system and submit the form
You can get user confirmation before sending the request by a checkbox asking whether to overwrite if the file exists. Then in your action do your IO stuff.
But if you still want to show the confirmation after sending the request I suggest you to use a custom interceptor that passes the request on both conditions of user confirmation and existence of the file. If the check didn't pass, you can return a custom result for confirmation part and resubmit the request. Just an idea.

Resources