Instantly share code, notes, and snippets.
Created
November 4, 2017 14:00
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save CCCBBBAAAHIGHSCORE/4e2b997ae277eea3c7db0759b14c7165 to your computer and use it in GitHub Desktop.
SidebarnoteGUI.ahk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance, Force | |
#NoTrayIcon | |
;Menu, Tray, Icon, D:\Users\name\Documents\AutoHotKey-Scripts-Master\img\noteicone2.ico | |
DetectHiddenWindows, On | |
GroupAdd, TotalGui, Tabs | |
GroupAdd, TotalGui, Notes | |
GroupAdd, TotalGui, NoteList | |
GroupAdd, TotalGui, separatetabfromnote | |
AutoSwitchToNewTab := true ; If true, when you create a new tab, it automatically switches to it | |
; Probably don't need all of these to be global, but I make a lot of global variables, because I love functions | |
global NoteWidth := 400 ; Width of note initially 300 | |
global TabWidth := 30 ; Width of tab | |
global WindowWidth := A_ScreenWidth ; Your monitor width | |
global WindowHeight := A_ScreenHeight ; Your monitor height... also your note height | |
global NoteHeight := WindowHeight - 40 | |
global NoteLocationX := WindowWidth - NoteWidth ; Where to put your notes on your monitor | |
global TabLocationX := NoteLocationX - TabWidth ; Where to put the tabs on your monitor | |
global ActiveTab := 1 ; What tab is currently active | |
global NotesNum ; How many notes there are for the currently active tab | |
global IniLoc := A_ScriptDir ; where the .ini file is located | |
global Ini := IniLoc "\tabs.ini" ; and its name, because I'm lazy | |
; This is for the GuiContextMenu for editing/removing the tab | |
; When right-clicking the control, AHK knows what you clicked | |
; As soon as you choose an option in the menu, it no longer knows | |
; So a global variable has to be set upon right click | |
; Weird, I know. But it works. | |
tabMenuClicked := "Tab1" | |
; Same for note(s) | |
noteMenuClicked := "note1" | |
GetTabs() | |
;;;;;; Build the tabs | |
Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow | |
Gui, Tabs:Color, c000007 ; cc0c0c0 | |
Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, + | |
BuildTabs() | |
Gui, Tabs:show, x%TabLocationX% y0 w%TabWidth% h%NoteHeight%, Tabs | |
WinSet, TransColor, c0c0c0, Tabs ; TransColor, c0c0c0 | |
WinSet, Transparent, 200, Tabs | |
Gui, separatetabfromnote:+AlwaysOnTop -Caption +ToolWindow | |
Gui, separatetabfromnote:Color, c999999 | |
Gui, separatetabfromnote:show, x%NoteLocationX% y0 w1 h%NoteHeight%, separatetabfromnote | |
;;;;;; Build the note area | |
Gui, Notes:+AlwaysOnTop -Caption +ToolWindow | |
Gui, Notes:Color, c000000 | |
Gui, Notes:Font, s18 cFFFFFF | |
Gui, Notes:Add, Text, x0 y0 h30 w%NoteWidth% Center gAddNote, Add Note | |
Gui, Notes:Font, s8 | |
Gui, Notes:Add, Text, x0 y33 h13 w%NoteWidth% Center, _________________________________________________________ | |
Gui, Notes:show, x%NoteLocationX% y0 h%NoteHeight% w%NoteWidth%, Notes ; h%WindowHeight% | |
WinSet, Transparent, 200, Notes ; 255 opaque -- 0 Transparent | |
Gui, NoteList:show,, NoteList | |
;;;;;; Put the notes from the active tab (app defaults to first tab) into Note window | |
BuildNotes(1) | |
Menu, NoteMenu, Add, Create New, AddNote | |
;;;;;;;; TabsGuiContextMenu | |
Menu, TabMenu, Add, Rename, EditTabName | |
Menu, TabMenu, Add | |
Menu, TabMenu, Add, Delete, DeleteTab | |
;;;;;;;; NotesGuiContextMenu | |
Menu, NoteListMenu, Add, Create New, AddNote | |
Menu, NoteListMenu, Add, Edit, EditNote | |
Menu, NoteListMenu, Add | |
Menu, NoteListMenu, Add, Delete, DeleteNote | |
WinHide, ahk_group TotalGui ; added here by clement, so, just after the gui load everything, it hides it, and show only when i press scrollLock, i needed this because otherwise when running the script (or if at startup, when pc boot) the gui showed... hope it doesnt break anything related to BuildNotes(function) | |
return ; first return, end of autoexecute | |
AddTab: | |
InputBox, NewTab, New Tab Name, What would you like to name your new tab?, , 290, 125 | |
if ErrorLevel | |
return | |
iniNum := TabNumber ? TabNumber + 1 : 1 | |
IniWrite, %NewTab%, %Ini%, tabs, %iniNum% | |
Gui, Tabs:Destroy | |
IfNotExist, Tab%iniNum% | |
FileCreateDir, Tab%iniNum% | |
Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow | |
Gui, Tabs:Color, cc0c0c0 | |
Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, + | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
GetTabs() | |
BuildTabs() | |
;Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
Gui, Tabs:show, x%TabLocationX% y0 w%TabWidth% h%NoteHeight%, Tabs | |
WinSet, Transparent, 200, Tabs | |
if AutoSwitchToNewTab | |
BuildNotes(iniNum) | |
return | |
AddNote: | |
Gui, WriteNote:Destroy | |
Gui, WriteNote:+AlwaysOnTop | |
Gui, WriteNote:Color, 1d1f21, 282a2e | |
;Gui, WriteNote:Font, cYellow, | |
Gui, WriteNote:Add, Edit, x10 y0 w300 h300 cWhite vNoteText, | |
Gui, WriteNote:Add, Button, x10 y310 h30 w300 Center gAddNoteFile, Add Note | |
Gui, WriteNote:Show, h340 w320, Note Editor | |
return | |
AddNoteFile: | |
GuiControlGet, NoteText, WriteNote:, , Text | |
Gui, WriteNote:Destroy | |
thisNoteNum := NotesNum + 1 | |
FileAppend, %NoteText%, Tab%ActiveTab%\note%thisNoteNum%.txt | |
Gui, NoteList:Destroy | |
BuildNotes(ActiveTab) | |
return | |
EditNote: | |
Gui, EditNote:Destroy | |
StringTrimLeft, nNum, noteMenuClicked, 4 | |
FileRead, note, Tab%ActiveTab%\note%nNum%.txt | |
Gui, EditNote:+AlwaysOnTop | |
Gui, EditNote:Color, 1d1f21, 282a2e | |
;Gui, EditNote:Add, Edit, x10 y0 w300 h300 vNoteText, % note | |
Gui, EditNote:Add, Edit, x10 y0 w300 h300 cWhite vEditNoteText, % note | |
Gui, EditNote:Add, Button, x10 y310 h30 w300 cWhite Center gEditNoteFile, Save Note | |
Gui, EditNote:Show, h340 w330, Note Editor | |
return | |
EditNoteFile: | |
StringTrimLeft, nNum, noteMenuClicked, 4 | |
;GuiControlGet, NoteText, EditNote:, , Text | |
GuiControlGet, EditNoteText, EditNote:, , Text | |
Gui, EditNote:Destroy | |
FileDelete, Tab%ActiveTab%\note%nNum%.txt | |
FileAppend, %EditNoteText%, Tab%ActiveTab%\note%nNum%.txt | |
;FileAppend, %NoteText%, Tab%ActiveTab%\note%nNum%.txt | |
Gui, NoteList:Destroy | |
BuildNotes(ActiveTab) | |
return | |
DeleteNote: | |
StringTrimLeft, nNum, noteMenuClicked, 4 | |
MsgBox, 4, Note Deletion Warning!, Are you sure you want to delete this note? ; option in msgbox is additionalbe, like 4+16 = 20 , it was set to 20, but i dont want the error sound | |
IfMsgBox, No | |
return | |
FileDelete, Tab%ActiveTab%\note%nNum%.txt | |
if (nNum < NotesNum) { | |
loopVar := NotesNum - nNum | |
Loop, % loopVar | |
{ | |
startNote := nNum + A_Index | |
endNote := startNote - 1 | |
FileMove, Tab%ActiveTab%\note%startNote%.txt, Tab%ActiveTab%\note%endNote%.txt | |
} | |
} | |
NotesNum-- | |
Gui, NotesList:Destroy | |
BuildNotes(ActiveTab) | |
return | |
EditTabName: | |
StringTrimLeft, tNum, tabMenuClicked, 3 | |
InputBox, tN, Rename Tab, What would you like to rename your tab?, , 290, 125 | |
if ErrorLevel | |
return | |
IniWrite, %tN%, %Ini%, tabs, %tNum% | |
; Due to auto-height, I have to destroy and recreate the tabs, otherwise just changing the text on the tab looks silly, | |
; if it's not the same length as the previous text | |
Gui, Tabs:Destroy | |
Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow | |
Gui, Tabs:Color, cc0c0c0 | |
Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, + | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
GetTabs() | |
BuildTabs() | |
Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
return | |
DeleteTab: | |
StringTrimLeft, tNum, tabMenuClicked, 3 | |
GuiControlGet, tN, Tabs:, %tabMenuClicked% | |
tabsNum := 0 | |
Loop, Files, Tab%tNum%\*.* | |
tabsNum++ | |
if (tabsNum > 0) | |
{ | |
MsgBox, 4, %tN% Tab Deletion Warning!, THIS WILL DELETE ALL NOTES UNDER THIS TAB!!`nThere are currently notes under this tab. Are you sure you wish to delete it? | |
IfMsgBox, No | |
return | |
} | |
FileRemoveDir, Tab%tNum%, 1 | |
; Because of the way the tabs are created, all subsequent folders and ini entries need to be adjusted | |
; to account for the loss of a number... for instance, if there are 6 tabs, and you delete #4, | |
; 5 and 6 need to be redefined as 4 and 5 respectively | |
if (tNum < TabNumber) { | |
loopVar := TabNumber - tNum | |
Loop, % loopVar | |
{ | |
startDir := tNum + A_Index | |
endDir := startDir - 1 | |
FileMoveDir, Tab%startDir%, Tab%endDir%, R | |
iniRead, tmp, %Ini%, tabs, %startDir% | |
iniWrite, %tmp%, %Ini%, tabs, %endDir% | |
} | |
} | |
iniDelete, %Ini%, tabs, %tabNumber% | |
tabNumber-- | |
Gui, Tabs:Destroy | |
Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow | |
Gui, Tabs:Color, cc0c0c0 | |
Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, + | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
GetTabs() | |
BuildTabs() | |
Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
return | |
TabPress: | |
StringTrimLeft, tabNum, A_GuiControl, 3 | |
BuildNotes(tabNum) | |
return | |
GetTabs() | |
{ | |
IniRead, Tabs, %Ini%, tabs | |
global TabList := [] | |
Loop, Parse, Tabs, `n | |
{ | |
val := A_LoopField | |
t := RegExMatch(val, "=") + 2 | |
val := SubStr(val, t, -1) | |
TabList.Insert(val) | |
} | |
global TabNumber := TabList.MaxIndex() | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
} | |
BuildTabs() | |
{ | |
global | |
Loop, % TabNumber | |
{ | |
index := A_Index | |
IniRead, TabName, %IniLoc%\tabs.ini, tabs, %index% | |
TabName := ConvertTabName(TabName) | |
if (A_Index = 1) | |
{ | |
Gui, Tabs:Add, Button, x0 y30 w%TabWidth% vTab%index% gTabPress, % TabName | |
WinSet, Transparent, 200, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
} | |
else | |
{ | |
Gui, Tabs:Add, Button, x0 w%TabWidth% vTab%index% gTabPress, % TabName | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
} | |
} | |
WinSet, TransColor, c0c0c0, Tabs | |
WinSet, Transparent, 200, Tabs | |
} | |
BuildNotes(tn) | |
{ | |
global | |
ActivateTab(tn) | |
notesNum := 0 | |
Loop, Files, Tab%ActiveTab%\*.* | |
notesNum++ | |
NotesNum := notesNum ? notesNum : 0 | |
Gui, NoteList:Destroy | |
Gui, NoteList:+AlwaysOnTop +OwnerNotes -Caption +ToolWindow | |
Gui, NoteList:Color, c000000 | |
Gui, NoteList:Font, s10 cFFFFFF | |
thisWidth := NoteWidth - 10 | |
Loop, % NotesNum | |
{ | |
FileRead, note, Tab%ActiveTab%\note%A_Index%.txt | |
Gui, NoteList:Add, Text, x5 w%thisWidth% vNote%A_Index% Center, % note "`n_______________________________" | |
} | |
Gui, NoteList:Show, x%NoteLocationX% y50 w%NoteWidth%, NoteList | |
} | |
ActivateTab(tn) | |
{ | |
Gui, Tabs:Font, | |
GuiControl, Tabs:Font, Tab%ActiveTab% | |
Gui, Tabs:Font, Bold | |
GuiControl, Tabs:Font, Tab%tn% | |
GuiControl, Tabs:Enable, Tab%ActiveTab% | |
GuiControl, Tabs:Disable, Tab%tn% | |
ActiveTab := tn | |
WinSet, Transparent, 200, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
} | |
ConvertTabName(name) | |
{ | |
newName = | |
Loop, Parse, name | |
{ | |
newName .= A_Index < StrLen(name) ? A_LoopField "`n" : A_LoopField | |
} | |
return newName | |
} | |
TabsGuiContextMenu: | |
tabMenuClicked := A_GuiControl | |
if !A_GuiControl | |
return | |
Menu, TabMenu, Show | |
return | |
NoteListGuiContextMenu: | |
if !A_GuiControl | |
return | |
noteMenuClicked := A_GuiControl | |
Menu, NoteListMenu, Show | |
return | |
NotesGuiContextMenu: | |
Menu, NoteMenu, Show | |
return | |
;/* remplaced with the next bloc, so when i start my pc, the gui is hidden | |
^#Break:: | |
WinGet, Style, Style, Tabs | |
If (Style & 0x10000000) ; 0x10000000 is WS_VISIBLE | |
WinHide, ahk_group TotalGui | |
Else | |
WinShow, ahk_group TotalGui | |
return | |
;*/ | |
; show : | |
/* | |
^#Break:: | |
BuildTabs() | |
Gui, Tabs:show, x%TabLocationX% y0 w%TabWidth%, Tabs | |
WinSet, TransColor, c0c0c0, Tabs | |
Gui, Notes:show, x%NoteLocationX% y0 h%NoteHeight% w%NoteWidth%, Notes ; h%WindowHeight% | |
WinSet, Transparent, 200, Notes ; 255 opaque -- 0 Transparent | |
Gui, NoteList:show,, NoteList | |
Gui, NoteList:Show, x%NoteLocationX% y50 w%NoteWidth%, NoteList | |
Return | |
Return | |
*/ | |
#Break:: ; but there shouldnt be a need to exit the app | |
Reload | |
Return | |
; to do , add a right click on tab gui, to add tab, as gui note add note on right click since, the + button is toooo hight for my mouse ^^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment