Skip to content

Commit

Permalink
v3.3-
Browse files Browse the repository at this point in the history
   - added ability to "pin" a note
   - added check to cancel editing if renaming is chosen while editing
   - adjusted note buttons' margins and padding
  • Loading branch information
freg-work authored Jun 12, 2017
1 parent 1bef292 commit 6ed0585
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 12 deletions.
31 changes: 28 additions & 3 deletions _note.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -317,4 +324,22 @@ button[disabled]:hover {
text-align: center;
margin: 0px 3px 1px 1px;
float: right;
}
}
#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;

}
75 changes: 72 additions & 3 deletions _note.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -70,6 +71,8 @@ var xElBeg = "<button class='x smallFont moveButtons' onclick='DelLine(this)' id
var xElEnd = "'>X</button>";
var renButtonHTML = "<button class='upperRightButton' onclick='RenameThisNote()'><span class='btnIcon'>&#9998;</span>Rename</button>";
var delButtonHTML = "<button class='upperRightButton' onclick='deleteNote();'><span class='btnIcon'>&#x2702;</span>Delete</button>";
var pinButtonHTML = "<button class='upperLeftButton' onclick='pinBox.innerHTML = \"\"; pin();'><span class='btnIcon'>&#9734;</span> Pin</button>";
var unpinButtonHTML = "<button class='upperLeftButton' onclick='unpin();'><span class='btnIcon'>&#9733;</span>Unpin</button>";
var moveButtonsHTMLBeg = "<button class='moveButtons smallFont uBut' id='u";
var moveButtonsHTMLMid = "' onclick='MoveUp(this)'>&uarr;</button> <button class='moveButtons smallFont dBut' id='d";
var moveButtonsHTMLEnd = "' onclick='MoveDown(this)'>&darr;</button>";
Expand All @@ -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 ----------
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -364,7 +369,8 @@ function showNotes(cNote) {
window[currentNote].className = 'noteButton activeNote';
var currentNoteDisplay = currentNote;
if (currentNote == "&") { currentNoteDisplay = "&#38;"; } // to deal w/ & as only char in title
noteTitle.innerHTML = "<div class='delBox'>" + renButtonHTML + delButtonHTML + "</div>" + "<span ondblclick='document.selection.empty(); RenameThisNote()'>" + currentNoteDisplay + "</span>";
noteTitle.innerHTML = "<div id='pinButton'></div><div class='delBox'>" + renButtonHTML + delButtonHTML + "</div>" + "<span ondblclick='RenameThisNote()'>" + currentNoteDisplay + "</span>";
showPinButton();
getLines(currentNote);
if (currentNote == prevNote) {
// if reloading the same note
Expand Down Expand Up @@ -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; }
}

Expand Down Expand Up @@ -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 ----------

Expand Down Expand Up @@ -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
Expand Down
29 changes: 23 additions & 6 deletions _note.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
' 13. Backup Location: current folder or user choice
' 14. Window width
' 15. Window height
' 16. Pinned note: <note name>/%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

Expand All @@ -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 = "<<<EOF>>>"
Const BackupPrefix = "backup_notes_"
Expand Down Expand Up @@ -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 + "<button class='noteButton' id='" + fs.GetBaseName(file) + "' onclick='showNotes(this.id)'>" + fs.GetBaseName(file) + "</button>"
if NOT fs.GetBaseName(file) = Opt16 then
NoteList.innerHTML = NoteList.innerHTML + "<button class='noteButton' id='" + fs.GetBaseName(file) + "' onclick='showNotes(this.id)'>" + fs.GetBaseName(file) + "</button>"
end if
end if
next
End Sub
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions note.hta
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<button id='aboutButton' class='upperRightButton' onclick='displayAbout();'><span class='btnIcon'>&#8505</span>&nbsp;&nbsp;About</button>
</div>

<div id='pinBox'></div>

<div id='noteList'></div>

<hr>
Expand Down

0 comments on commit 6ed0585

Please sign in to comment.