Skip to content

Default sketch names sort out of order #2068

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

Open
3 tasks done
drf5n opened this issue May 14, 2023 · 4 comments
Open
3 tasks done

Default sketch names sort out of order #2068

drf5n opened this issue May 14, 2023 · 4 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@drf5n
Copy link

drf5n commented May 14, 2023

Describe the problem

The default sketch name template of 'sketch_MMMDDx.ino' produces names that do not sort in a sane order.

sketch_apr03a	sketch_apr24a	sketch_dec20b	sketch_feb09a	sketch_feb23b	sketch_jan21a	sketch_mar08b	sketch_mar27b	sketch_nov18a
sketch_apr06a	sketch_apr25a	sketch_dec21a	sketch_feb09b	sketch_feb23c	sketch_jan22a	sketch_mar09a	sketch_mar27c	sketch_nov24a
sketch_apr07a	sketch_apr27a	sketch_dec28a	sketch_feb10a	sketch_feb24a	sketch_jan23a	sketch_mar12a	sketch_mar28b	sketch_nov24b
sketch_apr12a	sketch_dec05a	sketch_dec29a	sketch_feb14a	sketch_feb26a	sketch_jan23c	sketch_mar12b	sketch_mar28c	sketch_nov25a
sketch_apr13a	sketch_dec07a	sketch_feb01a	sketch_feb16a	sketch_feb28b	sketch_jan23d	sketch_mar16a	sketch_mar29a	sketch_oct22a
sketch_apr14a	sketch_dec10a	sketch_feb01b	sketch_feb16b	sketch_feb28c	sketch_jan24a	sketch_mar18a	sketch_mar30a	sketch_sep12b
sketch_apr15a	sketch_dec17a	sketch_feb01c	sketch_feb19a	sketch_jan02a	sketch_jan29a	sketch_mar18b	sketch_may02a	sketch_sep12c
sketch_apr16a	sketch_dec18a	sketch_feb01d	sketch_feb21a	sketch_jan03a	sketch_jan31a	sketch_mar20a	sketch_may02b
sketch_apr19a	sketch_dec18b	sketch_feb03a	sketch_feb21b	sketch_jan09a	sketch_mar05a	sketch_mar21a	sketch_may02c
sketch_apr21a	sketch_dec18c	sketch_feb03b	sketch_feb22a	sketch_jan11b	sketch_mar05b	sketch_mar25a	sketch_may03a
sketch_apr23a	sketch_dec20a	sketch_feb07a	sketch_feb23a	sketch_jan13a	sketch_mar08a	sketch_mar26a	sketch_nov07a

January sorts after February, April comes first, and December comes second.

Using a pattern like sketch_YYYYMMDDx would produce names which sort in a sane order.

To reproduce

Produce sketches with default names over the course of a year or multiple years.

Expected behavior

I would expect auto-generated sketch names to be created with an ISO-9660-ish name and sort in a sane, chronological order.

Either include the year and numeric month, or if awkward names that encourage renaming are the goal, use a simpler scheme like sketch_xxxx.

Arduino IDE version

2.1.0

Operating system

macOS

Operating system version

13.2.1

Additional context

Per @ptillisch, the code is here:

if (!sketchName) {
const monthNames = [
'jan',
'feb',
'mar',
'apr',
'may',
'jun',
'jul',
'aug',
'sep',
'oct',
'nov',
'dec',
];
const today = new Date();
const sketchBaseName = `sketch_${
monthNames[today.getMonth()]
}${today.getDate()}`;
const { config } = await this.configService.getConfiguration();
const sketchbookPath = config?.sketchDirUri
? FileUri.fsPath(config?.sketchDirUri)
: os.homedir();
// If it's another day, reset the count of sketches created today
if (this.lastSketchBaseName !== sketchBaseName)
this.sketchSuffixIndex = 1;
let nameFound = false;
while (!nameFound) {
const sketchNameCandidate = `${sketchBaseName}${sketchIndexToLetters(
this.sketchSuffixIndex++
)}`;
// Note: we check the future destination folder (`directories.user`) for name collision and not the temp folder!
const sketchExists = await exists(
path.join(sketchbookPath, sketchNameCandidate)
);
if (!sketchExists) {
nameFound = true;
sketchName = sketchNameCandidate;
}
}
this.lastSketchBaseName = sketchBaseName;
}

I'm not sure how that code pads the day numbers with zeros, but maybe something like this would work as I expect it should:

const sketchBaseName =`sketch_${today.getYear()}${today.getMonth()+1}${today.getDate()}`;

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@drf5n drf5n added the type: imperfection Perceived defect in any part of project label May 14, 2023
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself and removed type: imperfection Perceived defect in any part of project labels May 15, 2023
@ubidefeo
Copy link

thank you, @drf5n
this is some of that good old legacy coming from the Processing days.

Your proposal is interesting, especially from the point of view of someone who only accepts YYYYMMDDHHMMss formats for their files 🤣

@kittaakos
Copy link
Contributor

I would expect auto-generated sketch names to be created with an ISO-9660-ish name and sort in a sane, chronological order.

Hi, thanks for sharing your idea. Nice one!

@drf5n, would you be interested in contributing to this feature to IDE2? I am happy to guide you, or you can reference a very much related external contribution to change the default .ino file content with an advanced setting: #1559

A few remarks:

  • I would expect that the users can specify a valid date format as an advanced setting.
  • If no custom format is defined, IDE2 uses the current one.
  • IDE2 should fall back to the default behavior if an invalid date format is specified.
  • Custom date formats must not conflict with the sketch naming spec.

Alternatively, IDE2 can provide a set of predefined date formats (as an enum preference type) if such flexibility is not required.

@drf5n
Copy link
Author

drf5n commented May 16, 2023

@kittaakos -- I'm uncomfortable programming in .ts or how to modify the UI for advanced settings. Advanced settings seems impenetrable.

Regarding the example of the default.ino file, on my Mac, discovering the default sketch setting doesn't seem accessible through either "Arduino IDE/Preferences" or "Arduino IDE/Advanced":

image image

I can't grab a screenshot of it, but normal Mac apps use the option key to expose the more advanced alternative options. In this case, the option key changes the "Arduino IDE" menu to add an alternate Quit option: Option-Command-Q offers to "Quit and Keep Windows" I'd expect that Option-Command-, should be an enhancements of the Command-, Preferences/settings command to show the enhanced/advanced settings.

@kittaakos
Copy link
Contributor

Thanks for looking at the code, @drf5n. We will handle it later, then.

comfortable programming in .ts or how to modify the UI for advanced settings.

You don't need to change the UI at all. That's why I have referenced the other PR. Please see this comment:

I don't feel comfortable making change to the UI.

You do not have to. Checking your changeset, I am positive you can do it. Here are a few pointers:

@kittaakos kittaakos self-assigned this May 17, 2023
@kittaakos kittaakos removed their assignment Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

4 participants