Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #SingleInstance, Force
- DetectHiddenWindows, On
- GroupAdd, TotalGui, Tabs
- GroupAdd, TotalGui, Notes
- GroupAdd, TotalGui, NoteList
- 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 := 300 ; Width of note
- 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 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, cc0c0c0
- Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, +
- BuildTabs()
- Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
- WinSet, TransColor, c0c0c0, Tabs
- ;;;;;; 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%WindowHeight% w%NoteWidth%, Notes
- 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
- return
- 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, +
- GetTabs()
- BuildTabs()
- Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
- WinSet, TransColor, c0c0c0, Tabs
- if AutoSwitchToNewTab
- BuildNotes(iniNum)
- return
- AddNote:
- Gui, WriteNote:+AlwaysOnTop
- Gui, WriteNote:Add, Edit, x10 y0 w300 h300 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:
- StringTrimLeft, nNum, noteMenuClicked, 4
- FileRead, note, Tab%ActiveTab%\note%nNum%.txt
- Gui, EditNote:+AlwaysOnTop
- Gui, EditNote:Add, Edit, x10 y0 w300 h300 vNoteText, % note
- Gui, EditNote:Add, Button, x10 y310 h30 w300 Center gEditNoteFile, Save Note
- Gui, EditNote:Show, h340 w330, Note Editor
- return
- EditNoteFile:
- StringTrimLeft, nNum, noteMenuClicked, 4
- GuiControlGet, NoteText, EditNote:, , Text
- Gui, EditNote:Destroy
- FileDelete, Tab%ActiveTab%\note%nNum%.txt
- FileAppend, %NoteText%, Tab%ActiveTab%\note%nNum%.txt
- Gui, NoteList:Destroy
- BuildNotes(ActiveTab)
- return
- DeleteNote:
- StringTrimLeft, nNum, noteMenuClicked, 4
- MsgBox, 20, Note Deletion Warning!, Are you sure you want to delete this note?
- 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, +
- GetTabs()
- BuildTabs()
- Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
- WinSet, TransColor, c0c0c0, Tabs
- return
- DeleteTab:
- StringTrimLeft, tNum, tabMenuClicked, 3
- GuiControlGet, tN, Tabs:, %tabMenuClicked%
- tabsNum := 0
- Loop, Files, Tab%tNum%\*.*
- tabsNum++
- if (tabsNum > 0)
- {
- MsgBox, 20, %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, +
- GetTabs()
- BuildTabs()
- Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
- WinSet, TransColor, c0c0c0, 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()
- }
- 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
- else
- Gui, Tabs:Add, Button, x0 w%TabWidth% vTab%index% gTabPress, % TabName
- }
- }
- 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
- }
- 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
- F12::
- WinGet, Style, Style, Tabs
- If (Style & 0x10000000) ; 0x10000000 is WS_VISIBLE
- WinHide, ahk_group TotalGui
- Else
- WinShow, ahk_group TotalGui
- return
- F11::
- ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement