Tony Stone, I saw your
comment, but let's continue here. Discussions under commits are not welcome, as they are hard to find later. Our conversation of six users has dragged on anyway ))
I think I did it like this because I had concerns with directly using the string value of a GUI component... Maybe I was only concerned because I was truncating it.
When the shortening function is ready, of course, the path will need to be read from another place.
// should deal with an unsaved file but what about a "virtual file?"
if not FileExists(SourceFilePath) then
begin
if CurEditor.Modified then
ShowMessage('File not saved, cannot open folder.')
else
ShowMessage('Cannot find file on disk: ' + SourceFilePath);
Exit;
end;
Yes, you need to check if the file is new (virtual, not saved yet). But you also need to check if it is a file at all (for example, an IDE script can be opened). Only then you need to check the existence of the file:
if ActiveUnitInfo.InternalFile then exit;
if ActiveUnitInfo.IsVirtual then exit;
if not FileExistsUTF8(SourceFilePath) then exit;
This is just a code snippet. I will soon finish the patch for the context menu, and the same code can be used for the status bar. Also, there is a unit dependency issue, so the code itself should be in a different place.
By the way, I don't think that "
CurEditor.Modified" needs to be checked. For example, sometimes I specifically want to open the original file (before saving) to look at the original.