Sticky Notes 2.0

Post your working scripts, libraries and tools for AHK v1.1 and older
EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

Sticky Notes 2.0

Post by EntropicBlackhole » 25 Jan 2022, 18:29

I've decided to remake Sticky Notes, this time with different features, it also includes an update button, it's in the Settings window, it also stores the stuff in a more rational way, rather than pushing it all into one Ini file. I also got rid of many annoying things, but it's finally done

This is its current version (2.3)

Code: Select all

#SingleInstance, Force ;SN stands for Sticky Notes
Fol := "C:\Users\" . A_UserName "\AppData\Local\EPBHs Creations\Sticky Notes" ;SN Folder
Ini := Fol . "\Config.ini" ;Config File
URLFile := Fol . "\Update.epbh"
if !FileExist(Ini)
{
	Settings := " ;Settings
	(
[Settings]
EditColor=0xFFFFFF
TextColor=0x000000
AutomaticTextColor=1
ShowOnStartup=1
AutoSave=1
DarkMode=0
Password=0
Passcode=
TabNames=Untitled
	)"
	FileCreateDir, %Fol%
	FileAppend, %Settings%, %Ini%
	FileAppend, , %URLFile%
}
IniRead, EditC, %Ini%, Settings, EditColor ;Checks edit control color
IniRead, TextC, %Ini%, Settings, TextColor ;Checks text control color
IniRead, ATC, %Ini%, Settings, AutomaticTextColor ;Checks the automatic text color
IniRead, StartupShow, %Ini%, Settings, ShowOnStartup ;Checks if it'll show up on Startup
IniRead, AutoS, %Ini%, Settings, AutoSave ;Checks if it'll Autosave
IniRead, DarkMode, %Ini%, Settings, DarkMode ;Checks if DarkMode will be activated
IniRead, Password, %Ini%, Settings, Password ;Checks if it has a password
IniRead, Passcode, %Ini%, Settings, Passcode ;Checks what the password if
IniRead, TNames, %Ini%, Settings, TabNames ;Checks the tab names
URL := "https://raw.githubusercontent.com/EntropicBlackhole/Projects/main/Sticky%20Notes%202.1.ahk" ;This is the update link
Gui, Add, Tab3, hwndtab vcurrentTab gTab, %TNames% ;Adds the tab control
if (TNames = "Untitled")
	Gui, Add, Edit, w300 h200 gAutoSave c%TextC% ;if new, add Untitled
else
{
	tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
	Loop, Parse, TNames, |
	{
		Gui, Tab, %A_Index%
		FileRead, EditVar, %Fol%\%A_LoopField%.txt
		Gui, Add, Edit, w300 h200 gAutoSave c%TextC%, %EditVar%
	}
}
Gui, Color, , %EditC%
Gui, Tab
Gui, Add, Button, gSave, Save
Gui, Add, Button, gNew x+5, New
Gui, Add, Button, gDelete x+5, Delete
Gui, Add, Button, gChangeName x+5, Change Name
Gui, Add, Button, gAddFiles x+5, 🔺
Gui, Add, Button, gSettings x+5, ⚙
Gui, Add, CheckBox, gAOT x+5 yp+4, AOT
if (StartupShow = 1)
	GoSub, PasscodeCheckEnter
Gui, +HwndSN
Gui, New, , Settings
Gui, Settings:Add, Text, x10 y10 w50 h20, Edit Color
Gui, Settings:Add, Edit, y+0 w80 h20 gEditColor vEditColor, %EditC%
Gui, Settings:Add, ListView, x+10 w20 h20 +Background%EditC%
Gui, Settings:Add, Text, x10 y60 w50 h20, Text Color
Gui, Settings:Add, Edit, y+0 w80 h20 gTextColor vTextColor Disabled%ATC%, %TextC%
Gui, Settings:Add, ListView, x+10 w20 h20 +Background%TextC%
Gui, Settings:Add, CheckBox, x10 +Checked%ATC% gATColor vATColor, Automatic Text Color
Gui, Settings:Add, CheckBox, +Checked%StartupShow% vSoS, Show on Startup
Gui, Settings:Add, CheckBox, +Checked%AutoS% vAS, AutoSave
Gui, Settings:Add, CheckBox, +Checked%DarkMode% gDM vDM, Dark Mode
Gui, Settings:Add, CheckBox, +Checked%Password% gPW vPW w200, Password
Gui, Settings:Add, Edit, Password w120 vPC, %Passcode%
GuiControl, Settings:Enable%Password%, PC
Gui, Settings:Add, Button, gApply, Apply
Gui, Settings:+ToolWindow +Owner
if !(A_IsCompiled)
{
	Gui, Settings:Add, Button, gUpdate vUpdate xm+150 ym Disabled, Update
	URLDownloadToFile, %URL%, %URLFile%
	FileRead, UpdateCheck, %URlFile%
	if !(UpdateCheck = "404: Not Found")
		GuiControl, Settings:Enable, Update
}
if FileExist(Fol "\Sticky Notes.ini") ;this is  to check if version 1.0 exists on your device, if so, pass all the stuff onto here
{ ;yay backwards compatibality
	IniRead, OldTNames, %Fol%\Sticky Notes.ini, StickyNotes, TabNames
	Loop, Parse, % RTrim(OldTNames, "|"), |
	{
		IniRead, Stuff, %Fol%\Sticky Notes.ini, StickyNotes, %A_LoopField%
		NewTNames .= A_LoopField "|"
		Stuff := StrReplace(Stuff, "\", "`n")
		FileAppend, %Stuff%, %Fol%\%A_LoopField%.txt
	}
	TNames := RTrim(NewTNames, "|")
	IniWrite, %TNames%, %Ini%, Settings, TabNames
	IniRead, OldSettings, %Fol%\Sticky Notes.ini, Settings
	Loop, Parse, OldSettings, `n
	{
		StringSplit, OutSet, A_LoopField, =
		if (OutSet1 = "HotkeyShow")
			break
		IniWrite, %OutSet2%, %Ini%, Settings, %OutSet1%
	}
	FileDelete, %Fol%\Sticky Notes.ini
	Reload
}
return

Update:
MsgBox 0x24, Sticky Notes, There's an update pending. Update?
IfMsgBox, Yes
{
	GoSub, Save
	URLDownloadToFile, %URL%, %URLFile%
	FileRead, NewCode, %URLFile%
	Script := A_ScriptFullPath
	FileDelete, %Script%
	FileAppend, %NewCode%, %Script%
	Reload
}
return

Apply:
Gui, Settings:Submit, NoHide
if (PW = 1)
{
	InputBox, PasscodeCheck, Input your password, Input the password to confirm
	if (PasscodeCheck == PC)
		Goto, ApplyFinal
	else
		ToolTipTimer("Password was not the same, try again", 2000)
}
else
	Goto, ApplyFinal
return

ApplyFinal:
Gui, Settings:Submit
Gui, 1:Default
tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
Gui, Color, , %EditColor%
Loop, %tcount%
	GuiControl, +c%TextColor%, Edit%A_Index%
IniWrite, %EditColor%, %Ini%, Settings, EditColor
IniWrite, %TextColor%, %Ini%, Settings, TextColor
IniWrite, %ATColor%, %Ini%, Settings, AutomaticTextColor
IniWrite, %SoS%, %Ini%, Settings, ShowOnStartup
IniWrite, %DM%, %Ini%, Settings, DarkMode
IniWrite, %PW%, %Ini%, Settings, Password
IniWrite, %PC%, %Ini%, Settings, Passcode
Password := PW
Passcode := PC
return

PW:
Gui, Settings:Submit, NoHide
if (PW = 1)
{
	GuiControl, Settings:Enable, PC
	ToolTipTimer("Remember this password", 2000)
}
if (PW = 0)
{
	if (Passcode = "")
	{
		GuiControl, Settings:Disable, PC
		GuiControl, Settings:Text, PC
	}
	else
	{
		InputBox, PasswordCheck, Input your password, You must input your password first (Case Sensitive)
		if (PasswordCheck == Passcode)
		{
			GuiControl, Settings:Disable, PC
			GuiControl, Settings:Text, PC
		}
		else
		{
			GuiControl, Settings:, Button7, 1
			GuiControl, Settings:Text, Button7, Password is incorrect
			Sleep, 1000
			GuiControl, Settings:Text, Button7, Password
		}
	}
	
	
}
return

DM:
Gui, Settings:Submit, NoHide
GuiControl, Settings:Disable%DM%, EditColor
GuiControl, Settings:Disable%DM%, TextColor
GuiControl, Settings:Disable%DM%, ATColor
GuiControl, Settings:Text, EditColor, % (DM = 1) ? 0x1A1A1B : 0xFFFFFF
Goto, ATColor
return

ATColor:
Gui, Settings:Submit, NoHide
GuiControl, Settings:Disable%ATColor%, TextColor
if (ATColor = 1)
	TextColor := HexDec(EditColor) < 8355711 ? 0xFFFFFF : 0x000000
GuiControl, Settings:Text, TextColor, %TextColor%
GuiControl, Settings:+Background%TextColor%, SysListView322
return

EditColor:
TextColor:
Gui, Settings:Submit, NoHide
tempvar := %A_ThisLabel%
GuiControl, Settings:+Background%tempvar%, % (A_ThisLabel = "EditColor") ? "SysListView321" : "SysListView322"
if (A_ThisLabel = "EditColor")
	Goto, ATColor
return

Settings:
GuiControlGet, CheckifAOT, , Button7
WinGetPos, SnX, SnY, , , ahk_id %SN%
SnX += 70, SnY += 15
Gui, Settings:Show, x%SnX% y%SnY%, Settings
if CheckifAOT
	Gui, Settings:+AlwaysOnTop
return

AOT:
Winset, AlwaysOnTop, Toggle
return

Tab:
ControlGet, TabNum, Tab, , SysTabControl321, A
return

AutoSave:
Gui, Show, , *Sticky Notes
if (AutoS = 1)
	SetTimer, Save, -1000
return

^s::
if WinActive("ahk_id " SN)
	Goto, Save
return

Save:
Loop, Parse, TNames, |
{
	GuiControlGet, Edit, 1:, Edit%A_Index%
	FileDelete, %Fol%/%A_LoopField%.txt
	FileAppend, %Edit%, %Fol%/%A_LoopField%.txt
}
Gui, 1:Show, NoActivate, Sticky Notes ;the comment below was the old version
/*
ControlGet, CurrentTabName, Tab, , SysTabControl321, A
tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
Loop, %tcount%
{
	GuiControl, Choose, SysTabControl321, %A_Index%
	Gui, Submit, NoHide
	GuiControlGet, Edit, , Edit%A_Index%
	FileDelete, %Fol%/%currentTab%.txt
	FileAppend, Edit, %Fol%/%currentTab%.txt
	TabNames .= currentTab "|"
	SaveText := ""
}
IniWrite, %TabNames%, %Ini%, Settings, TabNames
TabNames := ""
GuiControl, Choose, SysTabControl321, %CurrentTabName%
Gui, Show, NoActivate, Sticky Notes
*/
return

New:
GuiControl, , SysTabControl321, Untitled
tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
Gui, Tab, %tcount%
Gui, Add, Edit, w300 h200 gAutoSave
GuiControl, Choose, SysTabControl321, %tcount%
TNames .= "|Untitled"
IniWrite, %TNames%, %Ini%, Settings, TabNames
FileAppend, , %Fol%\Untitled.txt
return

Delete:
Gui, +OwnDialogs
tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
if (tcount = 1)
	MsgBox, 48, Sorry, You are not allowed to delete the last tab remaining
else 
{
	MsgBox, 308, Wait, Are you sure you want to delete this sticky note?
	IfMsgBox, Yes
	{
		ControlGet, TabNum, Tab, , SysTabControl321, ahk_id %SN%
		Gui, Submit, NoHide
		Loop, Parse, TNames, |
		{
			if !(A_LoopField = currentTab)
				newNames .= A_LoopField "|"
		}
		TNames := RTrim(newNames, "|")
		newNames := ""
		Loop, %tcount%
			if (A_Index >= TabNum)
			{
				GuiControlGet, DelEdit, , % "Edit" A_Index+1
				GuiControl, , Edit%A_Index%, %DelEdit%
			}
		FileDelete, %Fol%\%currentTab%.txt
		GuiControl, , SysTabControl321, |%TNames%
		IniWrite, %TNames%, %Ini%, Settings, TabNames
		GuiControl, , Edit%tcount%
		/* ;some more stuff
		loop tcount, until you get to the current tab
		then using ControlGet add one to the index to get the next edit's value, place that in the current edit, and continue
		once you have reached the final one, stop
		
		
		==============
		ControlGet, CurrentTabName, Tab, , SysTabControl321, A ;CurrentTabName is the tab number for some reason
		tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
		Loop, % tcount-1
		{
			GuiControl, Choose, SysTabControl321, %A_Index%
			Gui, Submit, NoHide
			names .= "|" currentTab
		}
		GuiControl, Choose, SysTabControl321, %tcount%
		Gui, Submit, NoHide
		IniDelete, %Ini%, StickyNotes, %currentTab%
		GuiControl, Text, Edit%tcount%
		GuiControl, , SysTabControl321, %names%
		GoSub, Save
		GuiControl, Choose, SysTabControl321, %CurrentTabName%
		names := ""
		*/
	}
	IfMsgBox, No
		return
}
return

ChangeName: ; and also rewrite ini
Gui, Submit, NoHide
Gui, +OwnDialogs
ControlGet, TabNum, Tab, , SysTabControl321, ahk_id %SN%
InputBox, NewName, Sticky Notes, Insert a new name, , 130, 125
if (ErrorLevel = 0)
{
	Loop, Parse, TNames, |
		if (A_LoopField = NewName)
		{
			MsgBox, 0x30, Sticky Notes, You already have a file with this name
			return
		}
	Loop, Parse, TNames, |
		newNames .= (A_Index = TabNum) ? "|" NewName : "|" A_LoopField
	GuiControl, , SysTabControl321, %newNames%
	GuiControl, Choose, SysTabControl321, %TabNum%
	TNames := LTrim(newNames, "|")
	newNames := ""
	FileRead, tempvar, %Fol%\%currentTab%.txt
	FileAppend, %tempvar%, %Fol%\%NewName%.txt
	FileDelete, %Fol%\%currentTab%.txt
	IniWrite, %TNames%, %Ini%, Settings, TabNames
}
return

AddFiles: ;put the file name in TNames and also IniWrite it 
Gui, +OwnDialogs
FileSelectFile, File, 3, C:\Users\%A_UserName%\Downloads, Open a file, Only text (*.txt)
GuiDropFiles:
if (A_ThisLabel = "GuiDropFiles")
	File := A_GuiEvent
if (File = "")
	return
else
{
	tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
	SplitPath, File, , , , OutNameNoExt
	GuiControl, , SysTabControl321, %OutNameNoExt%
	FileRead, FileInput, %File%
	Gui, Tab, %tcount%
	Gui, Add, Edit, w300 h200 gAutoSave, %FileInput%
	TNames .= "|" OutNameNoExt
	IniWrite, %TNames%, Ini, Settings, TabNames
	/*
	GoSub, New
	tcount := DllCall("SendMessage", "UInt", tab, "UInt", 0x1304, Int, 0, Int, 0)
	GuiControl, Choose, SysTabControl321, %tcount%
	FileRead, FileInput, %File%
	Gui, Tab, %tcount%
	GuiControl, Text, Edit%tcount%, %FileInput%
	Loop, %tcount%
	{
		GuiControl, Choose, SysTabControl321, %A_Index%
		Gui, Submit, NoHide
		SplitPath, File, , , , OutNameNoExt
		names .= (A_Index = tcount) ? ("|" OutNameNoExt) : "|" currentTab
	}
	GuiControl, , SysTabControl321, %names%
	*/
}
return

PasscodeCheckEnter:
F4::
if (Password = 1)
{
	InputBox, PasswordCheck, Input your password, Input your password (Case Sensitive)
	if (ErrorLevel = 1)
		return
	else
	{
		if (PasswordCheck == Passcode)
			Gui, Show, , Sticky Notes
		else
			Goto, PasscodeCheckEnter
	}
}
else
	Gui, Show, , Sticky Notes
return

HexDec(DX) {
	DH := InStr(DX, "0x") > 0 ? "D" : "H"
	SetFormat Integer, %DH%
	return DX + 0
}
ToolTipTimer(Text, Timeout, x:="x", y:="y", WhichToolTip:=1) {
	If (x = "x")
		MouseGetPos, X
	If (y = "y")
		MouseGetPos, , Y
	ToolTip, %Text%, %X%, %Y%, %WhichToolTip%
	SetTimer, RemoveToolTip, -%Timeout%
	return
	
	RemoveToolTip:
	ToolTip
	return
}
Last edited by EntropicBlackhole on 29 Jan 2022, 18:11, edited 1 time in total.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Sticky Notes 2.0

Post by amateur+ » 27 Jan 2022, 19:57

Where do you use StrAmt(), ChooseColor() and BGRtoRGB()?
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

EntropicBlackhole
Posts: 40
Joined: 12 Jun 2021, 15:28

Re: Sticky Notes 2.0

Post by EntropicBlackhole » 29 Jan 2022, 17:49

amateur+ wrote:
27 Jan 2022, 19:57
Where do you use StrAmt(), ChooseColor() and BGRtoRGB()?
oh right i forgot those are functions that were in the other version but dont go here, i'll update, thanks for letting me know

gya
Posts: 25
Joined: 04 Nov 2021, 01:22

Re: Sticky Notes 2.0

Post by gya » 29 Jan 2022, 22:41

@EntropicBlackhole

I'm sorry but I don't like a script that writes unnecessarily in the "USERS" folder and uses a new extension (URLFile := Fol . "\Update.epbh") and that without at least warning !

Post Reply

Return to “Scripts and Functions (v1)”