Is there a way of suppressing the dialog asking if you want to save on a specific file? - vsix

When a user double clicks an item in one of my files, it opens a temporary file for them to edit using DTE. Once they are done editing that temporary file they close it and it adds to the parent file. That works great.
My issue is, is that when they go to close the temporary file, it asks them if they want to save. In this situation clicking no is the right thing to do else it asks you to save the file as something. Is there a way of changing this so that it doesn't ask the user and always just closes the file without saving it?
Thanks in advance.

While the DTE methods don't expose a way to do this, you could leverage IVsUIShellOpenDocument instead, and then explicitly add the RDT_DontSave, RDT_DontSaveAs, and potentially the RDT_DontAddtoMRU flags, via the grfOpenStandard argument passed to IVsUIShellOpenDocument.OpenStandardEditor or similar.
Alternatively, you could use IVsRunningDocumentTable.ModifyDocumentFlags to add the flags after the fact.
But for that, you'll need to retrieve the document cookie with something like IVsRunningDocumentTable2.FindAndLockDocumentEx.

Related

Is it possible to create a virtual editor in an extension

I want to process lots of files in my extension and editors have lots of useful methods that I need to use to process the content of a file with, but I don't want to open each file individually in VSC.
I have been able to read the files I plan on editing but how can I create an editor?
Can this be done?
Have you tried vscode.window.openTextDocument()?
openTextDocument(uri: Uri): Thenable<TextDocument>
Opens a document. Will return early if this document is already open. Otherwise the document is loaded and the didOpen-event fires.
That does not imply showing the editor, which is done with a separate vscode.window.showTextDocument() call, so it should qualify as "virtual".

Can you change the path of a database file?

I have an Excel spreadsheet on my desktop. I pull parameter data from it. I want to move it from my desktop to somewhere else. How do I do this?
Having something in the Data section as you show in your image means that it's referenced somewhere in your model. In this case you used an Excel object from the connectivity palette.
Your mission is to find that object and change the path there after moving it:
On this example, I have an Excel File element called parameters and if I want to change the path, I have to find the file again using the "..." button to the right of File:
When you do that, it automatically changes the path.
So here's all I could figure out. I had to change all of the instances where I refer to the database so the Population is "Initially empty".
Once I did this, I deleted the databases and had to save and close the model. Once I reopened it, the Resource had disappeared. I then moved the Excel file and re-imported it, but I'm sure there's a better way.

How to force Word to do a SaveAs on generated document

We have a system where we are generating a report as a Word document (using RDLC).
The report is created in a temporary directory, and then Word is launched to display it to the user.
Word is launched, and the report loaded by:
_wordApplication = (Word.Application)Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
object tempFileNameObj = documentPath;
_wordDocument = _wordApplication.Documents.Open(ref tempFileNameObj);
What I want is to convince Word that this is really a newly created, unsaved file, so it will give the user a SaveAs dialog when they save it (rather than save back to the temporary location).
Ideally, I would like to be able to specify the target directory, and offer a default name.
While the Word is being launched, I can do what I like using Automation, but after Word has been launched, my application will be disconnected from Word, and I would prefer not to leave any macros floating around in the document.
You can rename your .doc file to .dot (Word Template) and if you launch it afterwards, it will create a new File looking exactely like your .doc
If you're not using a macro I believe that the only way to archieve this would be to save the file that they will download be a read-only or user defined template file this way if they wan't to make changes to it they wil have to save it with another name in their computer to save the changes made. If you can use a macro you can archieve more options and even force a save as dialog when the document is opened or when it's closed. I hope this helps as I couldn't find any more information without using a macro.

Renaming file with filepicker.io

Here is my use case: the user will click a "save" link and will be presented with a filepicker.export() dialog, choose a location and name and save a file. Here's the exotic part: I won't have the file yet at that time. It needs to be downloaded first with a GET request, and then stored in filepicker. I won't know which file to start downloading until the user clicks "save".
This can be dealt with by first downloading the file when the user clicks "save", and only then displaying the filepicker.export() dialog. However, I find this cumbersome, since the user will have to wait for the download to finish to be able to choose a filename and location.
It would be much better to allow the user to first make their choice, for example "Dropbox/image.png", and store some sort of placeholder while the download is running: "Dropbox/image.png.part". Later, when the download finishes, I could write the data to the file and rename it to "Dropbox/image.png".
Here are my questions:
Is it possible to append ".part" to the filename that the user chose in the filepicker.export() call?
More importantly, while I know how to write to the file when the download is done, is there any way to rename it? I tried creating a new fpfile object with the same filepicker URL and a different filename, the new filename was ignored (though the write succeeded).
My recommendation would be to first call filepicker.export call on an empty file and allow the user to specify both the name of the file they would like and the location in their cloud storage. When the filepicker.export call finishes, it will pass an FPFile into the callback. From there, you can download any necessary contents you need and do a filepicker.write to save the contents to the location selected by the user.
There shouldn't be any need to rename the file, as the user has already provided the name they want to save the file under during the filepicker.export() call.

Prevent Save As Functionality

I need to prevent a document from being saved / saved as (say from ms word). I've looked around and I havn't quite found a satifying answer. I've considered EFS... but I don't think it prevents the user from saving the document as... (though it prevents access to the original source file). Any ideas outthere?
Run it on completely locked-down system with read-only disk, no network and no removable drives. Access to the computer must be phisically restricted as well.
This should prevent Save As from working, but still won't prevent document from being copied (someone may take photo of the screen and OCR it).
It usually isn't worth it to disable Save As, because you need access to the original in order to open it in the first place. There are always ways to copy a file.
I had the same issue come up when someone asked me to disable Save As for a PDF.
There is no way take an arbitrary document and modify it in such a way that it cannot be saved. You could modify a program such as Word not to allow Save or Save As but that would still allow someone to open and save the document with a different program or on a different machine.