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

Script settings not saved #605

Closed
Maboroshy opened this Issue Jun 4, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@Maboroshy
Contributor

Maboroshy commented Jun 4, 2017

Expected behaviour

Altered script settings persists and processed by the script.

Actual behaviour

When altering one of script settings, altered setting persists, others can go to their previous state.

Steps to reproduce

Use the script with many settings, like the one I'll post below. Start altering it's settings one by one.
I haven't yet found a system. Looks like only the last altered setting saved. Others goes to default. It gets much more complicated when the script is constantly changing while being developed.

Additional info

I've also checked app's db and it shows settings correctly. It's content is also altered in a corresponding manner.

Test script

import QtQml 2.0
import QOwnNotesTypes 1.0

Script {
    
    property string charSpaceName
    property string charSpaceLeftName
    property int charSpaceLeftTarget
    property string charNoSpaceName
    property string charNoSpaceLeftName
    property int charNoSpaceLeftTarget
    property string wordsName
    property string wordsLeftName
    property int wordsLeftTarget
    property string paragraphsName
    property string paragraphsLeftName
    property int paragraphsLeftTarget
    
    property variant settingsVariables: [
        {
            "identifier": "charSpaceName",
            "name": "Characters including spaces counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "Chars",
        },
        {
            "identifier": "charSpaceLeftName",
            "name": "Characters including spaces left until target counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "Chars left",
        },
        {
            "identifier": "charSpaceLeftTarget",
            "name": "Target number of characters including spaces",
            "description": "Put number of characters including spaces to count down to",
            "type": "integer",
            "default": "0",
        },
        {
            "identifier": "charNoSpaceName",
            "name": "Characters without spaces counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "",
        },
        {
            "identifier": "charNoSpaceLeftName",
            "name": "Characters without spaces left until target counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "",
        },
        {
            "identifier": "charNoSpaceLeftTarget",
            "name": "Target number of characters without spaces",
            "description": "Put number of characters without spaces to count down to",
            "type": "integer",
            "default": "0",
        },
        {
            "identifier": "wordsName",
            "name": "Words counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "Words",
        },
        {
            "identifier": "wordsLeftName",
            "name": "Words left until target counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "Words left",
        },
        {
            "identifier": "wordsLeftTarget",
            "name": "Target number of words",
            "description": "Put number of words to count down to",
            "type": "integer",
            "default": "0",
        },
        {
            "identifier": "paragraphsName",
            "name": "Paragraphs counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "",
        },
        {
            "identifier": "paragraphsLeftName",
            "name": "Paragraphs left until target counter name",
            "description": "Put a counter name here or leave empty to disable",
            "type": "string",
            "default": "",
        },
        {
            "identifier": "paragraphsLeftTarget",
            "name": "Target number of paragraphs",
            "description": "Put number of paragraphs to count down to",
            "type": "integer",
            "default": "0",
        }
    ]
    
    function init() {script.registerLabel("note stats")}
    
    function noteStats(note) {
        
        var entry = "<td align=center>%1 <b>%2</b></th>\n"
        var entryLeft = "<td align=center>%1 <b>%2 / %3</b></th>\n"
        
        if (charSpaceName !== "") {
            var charSpace = entry.arg(charSpaceName)
                                 .arg(note.noteText.length)
        }
        else {var charSpace = ""}
        
        if (charSpaceLeftName !== "") {
            var charSpaceLeft = entryLeft.arg(charSpaceLeftName)
                                         .arg(charSpaceLeftTarget - note.noteText.length)
                                         .arg(charSpaceLeftTarget)
        }
        else {var charSpaceLeft = ""}
        
        if (charNoSpaceName !== "") {
            var charNoSpace = entry.arg(charNoSpaceName)
                                   .arg(note.noteText.match(/[^ ]/gi).length)
        }
        else {var charNoSpace = ""}
        
        if (charNoSpaceLeftName !== "") {
            var charNoSpaceLeft = entryLeft.arg(charNoSpaceLeftName)
                                           .arg(charNoSpaceLeftTarget - note.noteText.match(/[^ ]/gi).length)
                                           .arg(charNoSpaceLeftTarget)
        }
        else {var charNoSpaceLeft = ""}
        
        if (wordsName !== "") {
            var words = entry.arg(wordsName).arg(note.noteText.split(/\s+/).length)
        }
        else {var words = ""}
        
        if (wordsLeftName !== "") {
            var wordsLeft = entryLeft.arg(wordsLeftName)
                                     .arg(wordsLeftTarget - note.noteText.split(/\s+/).length)
                                     .arg(wordsLeftTarget)
        }
        else {var wordsLeft = ""}
        
        if (paragraphsName !== "") {
            var paragraphs = entry.arg(paragraphsName)
                                  .arg((note.noteText.match(/^.*?\S/gm) || "").length)
        }
        else {var paragraphs = ""}   
        
        if (paragraphsLeftName !== "") {
            var paragraphsLeft = entryLeft.arg(paragraphsLeftName)
                                          .arg(paragraphsLeftTarget - (note.noteText.match(/^.*?\S/gm) || "").length)
                                          .arg(paragraphsLeftTarget)
        }
        else {var paragraphsLeft = ""} 
        
        script.setLabelText("note stats", "<table align=center width=90%>\n<tr>\n" + 
        charSpace + charSpaceLeft + charNoSpace + charNoSpaceLeft + words + wordsLeft + paragraphs + paragraphsLeft + 
        "</tr>\n</table>")
    }
    
    function noteOpenedHook(note) {noteStats(note)}
    function onNoteStored(note) {noteStats(note)}
} 
@pbek

This comment has been minimized.

Owner

pbek commented Jun 4, 2017

Thank you for reporting, I will try to reproduce your issue.

@pbek

This comment has been minimized.

Owner

pbek commented Jun 7, 2017

17.06.3

  • a problem with storing script settings if there is more than one setting was fixed

@pbek pbek added this to the 17.06.3 milestone Jun 7, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Jun 7, 2017

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

@Maboroshy

This comment has been minimized.

Contributor

Maboroshy commented Jun 7, 2017

Issue resolved. Settings work as they should. Looks like I have some pull requests to do on the weekend.

@Maboroshy Maboroshy closed this Jun 7, 2017

@pbek

This comment has been minimized.

Owner

pbek commented Jun 7, 2017

You have full access to the script repository. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment