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

Add filename and date to screenshot file if not Untitled #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

emajeru
Copy link

@emajeru emajeru commented Mar 30, 2020

Added
Monitors the TextDocument object of the file with selected text and uses the last calculated value to computer the filename when 'shoot' message is received. If the file that was referenced has never been saved the name will default to 'code.png'.

Fixes #96

Comment on lines -19 to +20
let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png'))
let lastUsedImageUri
let lastFile
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Set lastUserImageUri to undefined until it is assigned for the first time during the call to the shoot event.
  • Added variable to contain data on the last updated TextDocument object.

Comment on lines -77 to +78
defaultUri: lastUsedImageUri,
defaultUri: getFileName(),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Call to the getFileName function instead of using the global variable as it becomes a derived value.

function setupSelectionSync() {
return vscode.window.onDidChangeTextEditorSelection(e => {
if (e.selections[0] && !e.selections[0].isEmpty) {
lastFile = e.textEditor.document
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Monitor document selection during each update.

Comment on lines +123 to +140
function getFileName() {
let fileName = 'code.png'
if (!lastFile.isUntitled) {
const file = lastFile.uri.path.replace(/.*\/(.+[\..+]*)?(\..+)?$/, '$1$2')
const dateString = () => {
const date = new Date()
return date.toLocaleString()
.replace(/\//g, '-')
.replace(/,/, ' at')
.replace(/:/g, '.')
.replace(/(\d+)-(\d+)-(\d+)/, '$3-$1-$2')
}
fileName = `code - ${file} ${dateString()}.png`
}
lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop', fileName))
return lastUsedImageUri
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Computes the default file name with both the referenced document title and date appended.
  • Prefix of code remains to identify the document as a Polacode export.
  • Fallback to the original name code.png if the selected document is Untitled.
  • Set the global lastUsedImageUri variable for use.

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

Successfully merging this pull request may close these issues.

Feature Request: Add current filename to screenshot
1 participant