From 6ed0585c2fc80835f20dd33baef86962dc770221 Mon Sep 17 00:00:00 2001 From: freg-work Date: Mon, 12 Jun 2017 08:25:30 -0400 Subject: [PATCH] v3.3- - added ability to "pin" a note - added check to cancel editing if renaming is chosen while editing - adjusted note buttons' margins and padding --- _note.css | 31 ++++++++++++++++++++--- _note.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- _note.vbs | 29 ++++++++++++++++----- note.hta | 2 ++ 4 files changed, 125 insertions(+), 12 deletions(-) diff --git a/_note.css b/_note.css index bac2ec1..ef303a1 100644 --- a/_note.css +++ b/_note.css @@ -25,6 +25,13 @@ button[disabled]:hover { text-align: left; width: 87%; } +.upperLeftButton { + position: relative; + float: left; + margin-left: 5px; + text-align: left; + width: 74%; +} .btnIcon { padding: 0px 4px 0px 4px; position: relative; @@ -35,8 +42,8 @@ button[disabled]:hover { padding: 1px 0.7em 1px 0.7em; } .noteButton { - padding: 6px; - margin: 2px; + padding: 6px 3px; + margin: 1px; font-size: 1.2em; } .optionInput { @@ -317,4 +324,22 @@ button[disabled]:hover { text-align: center; margin: 0px 3px 1px 1px; float: right; -} \ No newline at end of file +} +#pinButton { + position: relative; + float: left; + width: 110px; + padding-bottom: 4px; +} +#pinBox { + display: none; + position: relative; + float: left; + border-right-style: groove; + margin: 5px; + padding: 2px 4px 2px 2px; + height: 80px; + overflow: hidden; + white-space: pre; + +} diff --git a/_note.js b/_note.js index 0ce96cb..d7e2904 100644 --- a/_note.js +++ b/_note.js @@ -16,6 +16,7 @@ var coords = document.getElementById('coords'); var undeleteButton = document.getElementById('undeleteButton'); var statusBar = document.getElementById('statusBar'); var statusBarText = document.getElementById('statusBarText'); +var pinBox = document.getElementById('pinBox'); var localFontDiv = [ document.getElementById('localFontDiv0'), document.getElementById('localFontDiv1'), @@ -70,6 +71,8 @@ var xElBeg = ""; +var unpinButtonHTML = ""; var moveButtonsHTMLBeg = " "; @@ -96,7 +99,7 @@ var defTextSize = 1; var sectionsCollapsed = 0; var sectionsTotal = 0; var currentNote, dummyVar, bgColor, i, currentX, currentY, oldX, oldY, offsetX, offsetY; -var lastLine, itemToEdit, itemTotal, statusTimer, prevNote, aboutCounter; +var lastLine, itemToEdit, itemTotal, statusTimer, prevNote, aboutCounter, pinned, pinOrUnpinHTML; // ------- declare functions ---------- @@ -179,6 +182,7 @@ function applyOptions() { if (Opt9 == 'cc') { currentX = Opt10; currentY = Opt11; } if (Opt12 == 'hide') { statusBar.style.display = 'none'; } else { statusBar.style.display = 'inline-block'; } + pinned = getPinned(); } function saveOptions() { @@ -334,6 +338,7 @@ function clearAll() { firstCall = false; setTimeout(function(){ firstCall = true; } , 250); GetFileList() + if (Opt16 != Default16) { pinBox.style.display = "none"; pinBox.firstChild.className = "noteButton"; pin(Opt16); } newNoteDiv.style.display = 'none'; optionsDiv.style.display = 'none'; inputDiv.style.display = 'none'; @@ -364,7 +369,8 @@ function showNotes(cNote) { window[currentNote].className = 'noteButton activeNote'; var currentNoteDisplay = currentNote; if (currentNote == "&") { currentNoteDisplay = "&"; } // to deal w/ & as only char in title - noteTitle.innerHTML = "
" + renButtonHTML + delButtonHTML + "
" + "" + currentNoteDisplay + ""; + noteTitle.innerHTML = "
" + renButtonHTML + delButtonHTML + "
" + "" + currentNoteDisplay + ""; + showPinButton(); getLines(currentNote); if (currentNote == prevNote) { // if reloading the same note @@ -509,7 +515,10 @@ function checkLocalFontInput(n) { function deleteNote() { // confirm, then call a sub in VBScript to delete currentNote var conf=''; - if (confirm("Are you sure you want to delete\n" + currentNote + "?", conf)) { DeleteThisNote() } + if (confirm("Are you sure you want to delete\n" + currentNote + "?", conf)) { + if (Opt16 == currentNote) { unpin(); } // if pinned note is being deleted, unpin it first + DeleteThisNote(); + } else { return; } } @@ -896,6 +905,65 @@ function checkCollapseExpandButtons() { else { document.getElementById('expandAllButton').disabled = false; } } +function pin() { + // pin current active note (if another note pinned, unpin it first) + if (pinned) { pinBox.style.display = "none"; } + var activeNote; + var cond = 'active'; + if (!!arguments[0]) { cond = 'init'; } + var buttons = document.getElementsByTagName('button'); + for (var i = 0; i < buttons.length; i++) { + if (cond == 'init') { // show pinned note on initialization; not the active note + if (buttons[i].innerText == Opt16) { + activeNote = buttons[i]; + break; + } + } + else { + if (buttons[i].className == 'noteButton activeNote') { + activeNote = buttons[i]; + break; + } + } + } + if (activeNote == undefined) { Opt16 = Default16; return; } // if pinned note is no longer there + pinBox.style.display = 'inline-block'; + pinBox.appendChild(activeNote); + pinned = true; + if (cond == 'active') { + Opt16 = activeNote.innerText; + WriteOptions(); + showPinButton(); + } + getFileList(); +} + +function unpin() { + // unpin current pinned note + pinBox.innerHTML = ""; + pinBox.style.display = "none"; + pinned = false; + Opt16 = Default16; + showPinButton(); + WriteOptions(); + GetFileList(); + showNotes(currentNote); +} + +function getPinned() { + // return the currently-pinned note, or false if none + if (Opt16 == "") { Opt16 = Default16; } + if (Opt16 == Default16 || pinBox.innerHTML == "") { return false; } + else {return Opt16; } // loop through notes here; verify Opt16 is a valid note +} + +function showPinButton() { + // show either pin or unpin button + pinned = getPinned(); + (pinned == currentNote) ? (pinOrUnpinHTML = unpinButtonHTML) : (pinOrUnpinHTML = pinButtonHTML); + document.getElementById('pinButton').innerHTML = pinOrUnpinHTML; +} + // ----------- declare event handlers ---------- @@ -963,6 +1031,7 @@ noteBody.attachEvent('onscroll', function() { setTimeout(function(){lastScrollPo clearAll(); getOffset(); applyOptions(); +if (Opt16 != Default16) { pin(Opt16); } // show pinned note if one has been set getDefaultSize(); window.resizeTo(Opt14, Opt15); // set initial size correctSize(); // to get correct window size diff --git a/_note.vbs b/_note.vbs index 3a16cc1..d0022a2 100644 --- a/_note.vbs +++ b/_note.vbs @@ -14,13 +14,14 @@ ' 13. Backup Location: current folder or user choice ' 14. Window width ' 15. Window height +' 16. Pinned note: /%none% ' ----- set up variables, constants, & objects ------ Option Explicit Dim fs, NewFileWithPath, rfile, afile, tfile, rofile, line, BackupLoc -Dim Opt1, Opt2, Opt3, Opt4, Opt5, Opt6, Opt7, Opt8, Opt9, Opt10, Opt11, Opt12, Opt13, Opt14, Opt15 +Dim Opt1, Opt2, Opt3, Opt4, Opt5, Opt6, Opt7, Opt8, Opt9, Opt10, Opt11, Opt12, Opt13, Opt14, Opt15, Opt16 Dim NoteWidth, NoteHeight, MidXPos, MidYPos Dim EditedString @@ -41,6 +42,7 @@ Const Default11 = "0" Const Default12 = "show" Const Default13 = ".\" ' no Default14/Default15; use NoteWidth & NoteHeight +Const Default16 = "%none%" Const OptionsFile = "config.txt" Const EOFConst = "<<>>" Const BackupPrefix = "backup_notes_" @@ -70,16 +72,19 @@ Opt12 = Default12 Opt13 = Default13 Opt14 = NoteWidth ' <-- get the correct values later, after determine default h&w Opt15 = NoteHeight +Opt16 = Default16 ' ------ subroutines & functions ----------- Sub GetFileList Dim file - NoteList.innerHtml = "" + NoteList.innerHTML = "" for each file in fs.GetFolder(notesDir).Files if fs.GetExtensionName(file) = "txt" then - NoteList.innerHtml = NoteList.innerHTML + "" + if NOT fs.GetBaseName(file) = Opt16 then + NoteList.innerHTML = NoteList.innerHTML + "" + end if end if next End Sub @@ -246,6 +251,10 @@ Sub GetOptions(dummyVar) if rofile.AtEndOfStream then rofile.close : OptionsCorrupted(14) : Exit Sub Opt15 = int(rofile.Readline) if Opt15 = "" then Opt15 = NoteHeight + ' get option 16 - pinned note + if rofile.AtEndOfStream then rofile.close : OptionsCorrupted(15) : Exit Sub + Opt16 = Lcase(rofile.Readline) + if Opt16 = "" then Opt16 = Default16 ' close file rofile.close Else @@ -269,12 +278,14 @@ Function GetOption(ThisOption) if ThisOption = "12" then GetOption = Opt12 if ThisOption = "13" then GetOption = Opt13 if ThisOption = "14" then GetOption = Opt14 - if ThisOption = "15" then GetOption = Opt15 + if ThisOption = "15" then GetOption = Opt15 + if ThisOption = "16" then GetOption = Opt16 End Function Sub OptionsCorrupted(numCorr) ' if options file not present or not formatted correctly, pass in any missing values & recreate it ' numCorr = number of options loaded succesfully + if numCorr < 16 then Opt16 = Default16 if numCorr < 15 then Opt15 = NoteHeight if numCorr < 14 then Opt14 = NoteWidth if numCorr < 13 then Opt13 = Default13 @@ -313,7 +324,8 @@ Sub WriteOptions tfile.WriteLine(Opt12) tfile.WriteLine(Opt13) tfile.WriteLine(Opt14) - tfile.WriteLine(Opt15) + tfile.WriteLine(Opt15) + tfile.WriteLine(Opt16) tfile.close if fs.FileExists(OptionsFile) then fs.DeleteFile(OptionsFile) fs.MoveFile TempFile, OptionsFile @@ -440,7 +452,10 @@ Sub DeleteAFile(thisFile) End Sub Sub RenameThisNote() - Dim NewName, OldName + Dim NewName, OldName, RenamedPinnedNote + RenamedPinnedNote = "" + document.selection.empty() + if editing = true then canceledEdit() NewName = InputBox("New name for this note:", "Note", currentNote, screen.availWidth/.45, screen.availWidth/.45) if NewName = "" then showStatus("No text entered") : exit sub NewName = checkForLeadingSpaces(NewName) @@ -450,6 +465,7 @@ Sub RenameThisNote() if IsNumeric(NewName) then checkFor1stCharNum(NewName) : exit sub if checkFor1stCharNum(mid(NewName,1,1)) then exit sub if CreateNewFile(NewName) = false then exit sub + if Opt16 = currentNote then RenamedPinnedNote = Opt16 : unpin() ' if pinned note is being deleted, unpin it first OpenRFile(currentNote) On Error Resume Next set tfile = fs.OpenTextFile(NewFileWithPath, 2, True) @@ -465,6 +481,7 @@ Sub RenameThisNote() DeleteThisNote OldName = currentNote currentNote = NewName + if RenamedPinnedNote <> "" then Opt16 = currentNote : pin(Opt16) : WriteOptions ' if pinned note is being deleted, unpin it first showNotes(currentNote) showStatus(AbbrevText(OldName) & " renamed to " & AbbrevText(NewName)) End Sub diff --git a/note.hta b/note.hta index 889eca6..ee1dc76 100644 --- a/note.hta +++ b/note.hta @@ -22,6 +22,8 @@ +
+