pbek / QOwnNotes

QOwnNotes is a plain-text file notepad and todo-list manager with Markdown support and Nextcloud / ownCloud integration.
https://www.qownnotes.org/
GNU General Public License v2.0
4.67k stars 413 forks source link

Note file naming by script engine keeps UUID #1704

Closed r00tr4v3n closed 4 years ago

r00tr4v3n commented 4 years ago

I might have missed a setting somewhere:

Expected behaviour

If I create a new note in the main window, it has a time stamp name as expected.

Actual behaviour

If a script creates a note, it keeps the UUID. This should be replaced later on, I guess.

        QString name =
            QStringLiteral("Note ") % Utils::Misc::createUuidString();

line

Steps to reproduce

Expand QOwnNotes Debug Information =========================== ## General Info **Current Date**: `Do. Apr. 23 13:06:00 2020` **Version**: `20.4.12` **Build date**: `Apr 21 2020` **Build number**: `701` **Platform**: `linux` **Operating System**: `Manjaro Linux` **Build architecture**: `x86_64` **Current architecture**: `x86_64` **Release**: `AUR` **Qt Version (build)**: `5.14.2` **Qt Version (runtime)**: `5.14.2` **Portable mode**: `no` **Settings path / key**: `/home/user/.config/PBE/QOwnNotes.conf` **Application database path**: `/home/user/.local/share/PBE/QOwnNotes/QOwnNotes.sqlite` **Application arguments**: `/usr/bin/QOwnNotes` **Qt Debug**: `0` **Locale (system)**: `en_US` **Locale (interface)**: *empty* **Primary screen resolution**: `1280x720` **Screen resolution(s)**: `1280x720, 1280x720` **Icon theme**: `Papirus-Adapta-Maia` **Notes in current note folder**: `37` **Calendar items**: `0` **Enabled scripts**: `1` ## Server Info **serverUrl**: *empty* **appIsValid**: `no` **notesPathExists**: *empty* **connectionErrorMessage**: *empty* ## Spellchecking **Enabled**: `true` **Selected language**: `auto` **Language codes**: `de_AT, de_BE, de_CH, de_DE, de_LI, de_LU` **Language names**: `Österreichisches Deutsch (Österreich), Deutsch (Belgien), Schweizer Hochdeutsch (Schweiz), Deutsch (Deutschland), Deutsch (Liechtenstein), Deutsch (Luxemburg)` **Application dictionaries path**: `/home/user/.local/share/PBE/QOwnNotes/dicts` ## Note folders **currentNoteFolderId**: `2` ### Note folder `default` **id**: `2` **isCurrent**: `yes` **activeTagId**: `-1` **localPath**: `/home/user/Downloads/test1` **remotePath**: `Notes` **cloudConnectionId**: `1` **isShowSubfolders**: `yes` **isUseGit**: `no` **activeNoteSubFolder name**: `test` **database file**: `/home/user/Downloads/test1/notes.sqlite` ## Cloud connections ### Cloud connection `Default` **id**: `1` **isCurrent**: `yes` **serverUrl**: *empty* **username**: *empty* ## Enabled scripts ### Script `testscript` **id**: `3` **path**: `/home/user/btsync/01_Development/05_Projects/Qt/scripts/testscript.qml` ## Settings **ActiveNoteHistoryItem** (NoteHistoryItem): `` **Debug/fakeOldVersionNumber** (bool): `false` **Debug/fileLogging** (bool): `false` **Editor/CurrentSchemaKey** (QString): `EditorColorSchema-cdbf28fc-1ddc-4d13-bb21-6a4043316a2f` **Editor/autoBracketClosing** (bool): `true` **Editor/autoBracketRemoval** (bool): `true` **Editor/disableCursorBlinking** (bool): `false` **Editor/editorWidthInDFMOnly** (bool): `true` **Editor/highlightCurrentLine** (bool): `true` **Editor/indentSize** (int): `4` **Editor/useTabIndent** (bool): `false` **Editor/vimMode** (bool): `false` **FileDialog/LastPath** (QString): `/home/user/btsync/01_Development/05_Projects/Qt/scripts` **FileDialog/LastPath-ScriptPath** (QString): `/home/user/btsync/01_Development/05_Projects/Qt/scripts` **IssueAssistantDialog/geometry** (QByteArray): `` **LastUpdateCheck** (QDateTime): `2020-04-23T12:56:56.128` **LinkDialog/geometry** (QByteArray): `` **LocalTrashDialog/geometry** (QByteArray): `` **MainWindow/geometry** (QByteArray): `` **MainWindow/mainToolBar.iconSize** (int): `16` **MainWindow/menuBarGeometry** (QByteArray): `` **MainWindow/noteSubFolderTreeWidgetExpandState-2** (QStringList): `folderA, folderB, folderB/subB` **MainWindow/noteTextEdit.code.font** (QString): `Cantarell,10,-1,5,50,0,0,0,0,0` **MainWindow/noteTextEdit.font** (QString): `Cantarell,10,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.code.font** (QString): `Cantarell,10,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.font** (QString): `Cantarell,10,-1,5,50,0,0,0,0,0` **MainWindow/noteTextView.ignoreCodeFontSize** (bool): `true` **MainWindow/noteTextView.rtl** (bool): `false` **MainWindow/noteTextView.underline** (bool): `true` **MainWindow/noteTextView.useEditorStyles** (bool): `true` **MainWindow/noteTextView.useInternalExportStyling** (bool): `true` **MainWindow/showNotesFromAllNoteSubFolders** (bool): `false` **MainWindow/tagTreeWidgetExpandState-1** (QString): `1` **MainWindow/tagTreeWidgetExpandState-2** (QStringList): `4` **NoteFolder-2/allowDifferentNoteFileName** (bool): `true` **NoteHistory-2** (QVariantList): `` **NoteHistoryCurrentIndex-2** (int): `30` **PiwikClientId** (QString): `` **ScriptRepositoryDialog/geometry** (QByteArray): `` **ScriptRepositoryDialog/mainSplitterState** (QByteArray): `` **SearchEngineId** (int): `2` **SettingsDialog/geometry** (QByteArray): `` **SettingsDialog/mainSplitterState** (QByteArray): `` **Shortcuts/MainWindow-customAction_meetingNote** (QKeySequence): *empty* **ShowSystemTray** (bool): `false` **StartHidden** (bool): `false` **TagAddDialog/geometry** (QByteArray): `` **WelcomeDialog/geometry** (QByteArray): `` **acceptAllExternalModifications** (bool): `false` **allowNoteEditing** (bool): `true` **allowOnlyOneAppInstance** (bool): `true` **appMetrics/disableAppHeartbeat** (bool): `false` **appMetrics/disableTracking** (bool): `false` **appMetrics/notificationShown** (QString): `true` **automaticNoteFolderDatabaseClosing** (bool): `false` **checkSpelling** (bool): `true` **closeTodoListAfterSave** (bool): `false` **cryptoKey** (QString): `` **currentNoteFolderId** (QString): `2` **currentWorkspace** (QString): `initial` **cursorWidth** (int): `1` **customNoteFileExtensionList** (QStringList): *empty* **darkMode** (bool): `true` **darkModeColors** (bool): `true` **darkModeIconTheme** (bool): `true` **darkModeTrayIcon** (bool): `true` **defaultNoteFileExtension** (QString): `md` **demoNotesCreated** (QString): `true` **disableAutomaticUpdateDialog** (bool): `true` **disableSavedSearchesAutoCompletion** (bool): `false` **dockWasInitializedOnce** (QString): `true` **enableNoteTree** (bool): `false` **enableSocketServer** (bool): `true` **externalEditorPath** (QString): *empty* **fullyHighlightedBlockquotes** (bool): `false` **gitCommitInterval** (int): `30` **gitExecutablePath** (QString): *empty* **gitLogCommand** (QString): *empty* **guiFirstRunInit** (bool): `true` **ignoreAllExternalModifications** (bool): `false` **ignoreAllExternalNoteFolderChanges** (bool): `false` **ignoreNoteSubFolders** (QString): `^\.` **imageScaleDown** (bool): `false` **imageScaleDownMaximumHeight** (int): `1024` **imageScaleDownMaximumWidth** (int): `1024` **initialLayoutIdentifier** (QString): `minimal` **insertTimeFormat** (QString): *empty* **interfaceFontSize** (int): `11` **interfaceLanguage** (QString): *empty* **interfaceStyle** (QString): `Fusion` **internalIconTheme** (bool): `true` **itemHeight** (int): `20` **legacyLinking** (bool): `false` **localTrash/autoCleanupDays** (int): `30` **localTrash/autoCleanupEnabled** (bool): `true` **localTrash/supportEnabled** (bool): `true` **localTrashSplitterSizes** (QByteArray): `` **markdownHighlightingEnabled** (bool): `true` **navigationPanelHideSearch** (bool): `true` **networking/ignoreSSLErrors** (bool): `true` **networking/proxyType** (int): `2` **newNoteAskHeadline** (bool): `false` **noteEditIsCentralWidget** (bool): `true` **noteListPreview** (bool): `false` **noteSaveIntervalTime** (int): `10` **noteSubfoldersPanelDisplayAsFullTree** (bool): `true` **noteSubfoldersPanelHideSearch** (bool): `true` **noteSubfoldersPanelOrder** (int): `0` **noteSubfoldersPanelShowFullPath** (bool): `false` **noteSubfoldersPanelShowNotesRecursively** (bool): `true` **noteSubfoldersPanelShowRootFolderName** (bool): `true` **noteSubfoldersPanelSort** (int): `0` **notesPanelOrder** (int): `0` **notesPanelSort** (int): `0` **notesPath** (QString): `/home/user/Downloads/test1` **notifyAllExternalModifications** (bool): `false` **overrideInterfaceFontSize** (bool): `false` **ownCloud/supportEnabled** (bool): `false` **ownCloud/todoCalendarBackend** (int): `3` **ownCloud/todoCalendarCalDAVPassword** (QString): `` **ownCloud/todoCalendarCalDAVServerUrl** (QString): *empty* **ownCloud/todoCalendarCalDAVUsername** (QString): *empty* **ownCloud/todoCalendarCloudConnectionId** (int): `1` **ownCloud/todoCalendarDisplayNameList** (QStringList): *empty* **ownCloud/todoCalendarEnabledList** (QStringList): *empty* **ownCloud/todoCalendarEnabledUrlList** (QStringList): *empty* **ownCloud/todoCalendarUrlList** (QStringList): *empty* **ownCloudInfo/appIsValid** (bool): `false` **ownCloudInfo/connectionErrorMessage** (QString): *empty* **ownCloudInfo/notesPathExistsText** (QString): *empty* **ownCloudInfo/serverVersion** (QString): *empty* **recentNoteFolders** (QString): `/home/user/btsync/02_Notes` **restoreCursorPosition** (bool): `true` **restoreLastNoteAtStartup** (bool): `true` **savedSearches/noteFolder-2** (QStringList): `Note 745bba82-010c-4396-a917-e8492bbb604b, Note 84211d9f-3635-4078-b87b-d49f84973cd4, Note 20bebd85-8db5-49b0-96eb-cf46a338a9ed, Note c5a3f724-35fa-435e-b6df-73e38cb40055, Note d04556f6-9752-4172-ab4f-85953093a97e, Note c2a2d4b1-8d63-484f-8702-cbf920c719c9, Note 64e31ca0-2c42-4b02-92d4-2455dec24c49, Note 518d179e-0f0e-471b-81e5-fb01c7fc0205, Note 4fcba4b4-084d-4f53-a7ec-10dafa54a1ee, Note dea7a624-8995-4353-8f42-5197bea09146, Note 2020-04-23T11.53.34, Note 2020-04-23T11.53.22, Note 2020-04-23T11.53.15, Note 2020-04-23T11.53.14, Note 4d954d1b-4c5d-4051-a41f-46e49a2ba416, Note d4dfc2fa-9ccc-4304-acbf-5587dd9418c1, Note 2020-04-23T11.44.29, Note 1dfee2e9-786d-4779-b058-3ae70b410610, Note e1478caa-2ca2-4e82-9e7a-ca6ad74ddc05, Note 993c4c42-9cc9-46aa-b6ff-b6bdf1b14837, Note bb73ee64-55d1-4a5a-a8d6-128df1fbbfc8, Note 333a6578-c992-4223-b509-d709d0d66d20, Note 2020-04-22T15.16.58, Note 2020-04-21T21.36.14` **showMatches** (bool): `true` **showMenuBar** (bool): `true` **showStatusBar** (bool): `true` **spellCheckLanguage** (QString): `auto` **systemIconTheme** (bool): `false` **tagWasAddedToNote** (QString): `true` **taggingShowNotesRecursively** (bool): `true` **tagsPanelHideSearch** (bool): `true` **tagsPanelOrder** (int): `0` **tagsPanelSort** (int): `0` **todoCalendarSupport** (bool): `true` **toolbar/1/items** (QStringList): `action_New_note, action_Find_note, action_Remove_note, action_Open_note_in_external_editor, actionShow_local_trash, actionAllow_note_editing, , action_Back_in_note_history, action_Forward_in_note_history, , action_Find_text_in_note, actionReplace_in_current_note, , actionShow_versions, actionShow_trash, actionShare_note, , actionOpen_List` **toolbar/1/name** (QString): `mainToolBar` **toolbar/1/title** (QString): `main toolbar` **toolbar/2/items** (QStringList): `actionFormat_text_bold, actionFormat_text_italic, actionStrike_out_text, actionInsert_code_block, actionInsert_block_quote` **toolbar/2/name** (QString): `formattingToolbar` **toolbar/2/title** (QString): `formatting toolbar` **toolbar/3/items** (QStringList): `actionInsert_Link_to_note, actionInsert_image, actionInsert_current_time` **toolbar/3/name** (QString): `insertingToolbar` **toolbar/3/title** (QString): `inserting toolbar` **toolbar/4/items** (QStringList): `action_Encrypt_note, actionEdit_encrypted_note, actionDecrypt_note` **toolbar/4/name** (QString): `encryptionToolbar` **toolbar/4/title** (QString): `encryption toolbar` **toolbar/5/items** (QStringList): `actionWorkspaceComboBox, actionStore_as_new_workspace, actionRemove_current_workspace, actionRename_current_workspace, actionSwitch_to_previous_workspace, actionUnlock_panels, , actionToggle_distraction_free_mode, action_Increase_note_text_size, action_Decrease_note_text_size, action_Reset_note_text_size` **toolbar/5/name** (QString): `windowToolbar` **toolbar/5/title** (QString): `window toolbar` **toolbar/6/items** (QStringList): `action_Quit` **toolbar/6/name** (QString): `quitToolbar` **toolbar/6/title** (QString): `quit toolbar` **toolbar/size** (int): `6` **useNoteFolderButtons** (bool): `false` **useUNIXNewline** (bool): `false` **webSocketServerService/bookmarksNoteName** (QString): `Bookmarks` **webSocketServerService/bookmarksTag** (QString): `bookmarks` **webSocketServerService/port** (int): `22222` **workspace-initial/name** (QString): `Minimal` **workspace-initial/noteSubFolderDockWidgetVisible** (QString): `true` **workspace-initial/windowState** (QByteArray): `` **workspaces** (QString): `initial` ## System environment **SHELL**: `/bin/bash` **CSF_MDTVTexturesDirectory**: `/usr/share/opencascade/resources/Textures` **XDG_SESSION_PATH**: `/org/freedesktop/DisplayManager/Session0` **CSF_DrawPluginDefaults**: `/usr/share/opencascade/resources/DrawResources` **CSF_LANGUAGE**: `us` **CSF_MIGRATION_TYPES**: `/usr/share/opencascade/resources/StdResource/MigrationSheet.txt` **GRADLE_HOME**: `/usr/share/java/gradle` **DESKTOP_SESSION**: `mate` **LC_MONETARY**: `de_DE.UTF-8` **CSF_OCCTResourcePath**: `/usr/share/opencascade/resources` **CSF_STEPDefaults**: `/usr/share/opencascade/resources/XSTEPResource` **EDITOR**: `/usr/bin/nano` **GTK_MODULES**: `canberra-gtk-module` **XDG_SEAT**: `seat0` **PWD**: `/home/user` **XDG_SESSION_DESKTOP**: `mate` **LOGNAME**: `user` **QT_QPA_PLATFORMTHEME**: `qt5ct` **XDG_SESSION_TYPE**: `x11` **DRAWHOME**: `/usr/share/opencascade/resources/DrawResources` **XAUTHORITY**: `/home/user/.Xauthority` **CSF_StandardLiteDefaults**: `/usr/share/opencascade/resources/StdResource` **XDG_GREETER_DATA_DIR**: `/var/lib/lightdm-data/user` **GTK2_RC_FILES**: `/home/user/.gtkrc-2.0` **HOME**: `/home/user` **LANG**: `en_US.UTF-8` **XDG_CURRENT_DESKTOP**: `MATE` **XDG_SEAT_PATH**: `/org/freedesktop/DisplayManager/Seat0` **CSF_ShadersDirectory**: `/usr/share/opencascade/resources/Shaders` **CSF_EXCEPTION_PROMPT**: `1` **CSF_XmlOcafResource**: `/usr/share/opencascade/resources/XmlOcafResource` **CSF_SHMessage**: `/usr/share/opencascade/resources/SHMessage` **XDG_SESSION_CLASS**: `user` **USER**: `user` **CSF_StandardDefaults**: `/usr/share/opencascade/resources/StdResource` **CSF_IGESDefaults**: `/usr/share/opencascade/resources/XSTEPResource` **DISPLAY**: `:0` **CSF_XCAFDefaults**: `/usr/share/opencascade/resources/StdResource` **SHLVL**: `0` **LC_MEASUREMENT**: `de_DE.UTF-8` **XDG_VTNR**: `7` **CSF_PluginDefaults**: `/usr/share/opencascade/resources/StdResource` **CSF_TObjMessage**: `/usr/share/opencascade/resources/TObj` **XDG_SESSION_ID**: `2` **CASROOT**: `/usr` **MOZ_PLUGIN_PATH**: `/usr/lib/mozilla/plugins` **XDG_RUNTIME_DIR**: `/run/user/1000` **LC_TIME**: `de_DE.UTF-8` **CSF_XSMessage**: `/usr/share/opencascade/resources/XSMessage` **MMGT_CLEAR**: `1` **XDG_DATA_DIRS**: `/home/user/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop` **PATH**: `/home/user/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin` **CSF_TObjDefaults**: `/usr/share/opencascade/resources/StdResource` **GDMSESSION**: `mate` **DBUS_SESSION_BUS_ADDRESS**: `unix:path=/run/user/1000/bus` **HG**: `/usr/bin/hg` **MAIL**: `/var/spool/mail/user` **DRAWDEFAULT**: `/usr/share/opencascade/resources/DrawResources/DrawDefault` **LC_NUMERIC**: `de_DE.UTF-8` **MATE_DESKTOP_SESSION_ID**: `this-is-deprecated` **SESSION_MANAGER**: `local/user:@/tmp/.ICE-unix/1791,unix/user:/tmp/.ICE-unix/1791` **GTK_OVERLAY_SCROLLING**: `0` **SSH_AUTH_SOCK**: `/run/user/1000/keyring/ssh` **QT_AUTO_SCREEN_SCALE_FACTOR**: `0` **QT_SCALE_FACTOR**: `2`

Relevant log output in the Log panel

log [12:58:53] [scripting] loading script file: /.../scripts/testscript.qml [12:58:53] [status] Stored current note to disk [12:58:54] [status] The scripting engine was reloaded [12:58:55] [status] Stored 1 note(s) to disk
pbek commented 4 years ago

Can you please explain in more detail and step by step what you did, what happened and what you expected (see issue template). Can you please post the output from the debug settings (see issue template). And is there any useful log output if you enable the log panel (see Window / Panels)? Please make sure you also enable debug logging.

r00tr4v3n commented 4 years ago

I found a reason for the behaviour: Without the "allow note file name to be different from heading" setting the UUID turns into the expected file name within seconds.

pbek commented 4 years ago

Of course, the reason I used a uuid in the script you maybe saw was to have unique temporary name to use before QON sets one.

pbek commented 4 years ago

If you want to use your own file names you need to turn mentioned checkbox on.

r00tr4v3n commented 4 years ago

How do I change the file name? I checked with the Meeting Script. Is it supposed to keep the UUID when having custom file names enabled?

/**
 * Creates a new note
 *
 * @param text the note text
 */
void ScriptingService::createNote(QString text);
pbek commented 4 years ago

20.4.16

pbek commented 4 years ago

There now is a new release, could you please test it and report if it works for you?

r00tr4v3n commented 4 years ago

Thank you for the update. It seems to work but gives me trouble in combination with yaml tags or other note changing scripts:

This does call the tag hook but does not save the tags.

            script.createNote(headline);
            const currentNote = script.currentNote();

            // rename the note file if needed
            if (currentNote.allowDifferentFileName()) {
                currentNote.renameNoteFile(headline);
                mainWindow.buildNotesIndexAndLoadNoteDirectoryList(false, true);
            }
            script.tagCurrentNote("defaultTag");

In order of

pbek commented 4 years ago

maybe only call mainWindow.buildNotesIndexAndLoadNoteDirectoryList(false, true); in the end, it has the potential to mess things up.

r00tr4v3n commented 4 years ago

No, that does not change anything. I suspect the rename operation messes up the currentNote() function. Maybe a hint in the docs to use renameNoteFile() as last operation suffices for now?

pbek commented 4 years ago

I suspect the rename operation messes up the currentNote() function.

Does it? Is a note folder reload triggered for you if you call it? You could call curentNote()again.

r00tr4v3n commented 4 years ago

I've tried that but in this case the changes to the note (yaml header) are not present.

pbek commented 4 years ago

I've tried that but in this case the changes to the note (yaml header) are not present.

which changes should be present?

r00tr4v3n commented 4 years ago

The entire yaml header is missing. The script is called and executed but the result seems to be overwritten.

pbek commented 4 years ago

Yaml headers? Which script are we talking about? And which part of the script? :smile:

r00tr4v3n commented 4 years ago

Epsilon-note-tags: since the tag hook is called, the script shouldn't be the issue.

pbek commented 4 years ago

Why do you want add tags to a note via QOwnNotes in a tagging hook? You are supposed to only work on the note text and provide the updated note text via the return command.

pbek commented 4 years ago

Or better question: What are you trying to achieve?

r00tr4v3n commented 4 years ago

Or better question: What are you trying to achieve?

I'm just trying to ascertain if this is a bug or a wrong usage of the script api on my part (and the current meetings script). It works for fine with the correct execution order. There are two scripts: epsilon-tags and meetings with the renameFile call In combination, the yaml tags are not added to the note. I fixed that in my fork by changing the execution order to

pbek commented 4 years ago

Ah, ok. Just make sure not to do any note operations inside a tagging hook. :)

r00tr4v3n commented 4 years ago

Will do, thank you!