Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2.  
  3. AutoSwitchToNewTab := true ; If true, when you create a new tab, it automatically switches to it
  4.  
  5. ; Probably don't need all of these to be global, but I make a lot of global variables, because I love functions
  6. global NoteWidth := 300  ; Width of note
  7. global TabWidth := 30  ; Width of tab
  8. global WindowWidth := A_ScreenWidth  ; Your monitor width
  9. global WindowHeight := A_ScreenHeight ; Your monitor height... also your note height
  10. global NoteLocationX := WindowWidth - NoteWidth  ; Where to put your notes on your monitor
  11. global TabLocationX := NoteLocationX - TabWidth  ; Where to put the tabs on your monitor
  12. global ActiveTab := 1  ; What tab is currently active
  13. global NotesNum  ; How many notes there are for the currently active tab
  14.  
  15. global IniLoc := A_ScriptDir  ; where the .ini file is located
  16. global Ini := IniLoc "\tabs.ini"  ; and its name, because I'm lazy
  17.  
  18. ; This is for the GuiContextMenu for editing/removing the tab
  19. ; When right-clicking the control, AHK knows what you clicked
  20. ; As soon as you choose an option in the menu, it no longer knows
  21. ; So a global variable has to be set upon right click
  22. ; Weird, I know.  But it works.
  23. tabMenuClicked := "Tab1"  
  24. ; Same for note(s)
  25. noteMenuClicked := "note1"
  26.  
  27. GetTabs()
  28.  
  29. ;;;;;; Build the tabs
  30. Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow
  31. Gui, Tabs:Color, cc0c0c0
  32. Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, +
  33. BuildTabs()
  34. Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
  35. WinSet, TransColor, c0c0c0, Tabs
  36.  
  37. ;;;;;; Build the note area
  38. Gui, Notes:+AlwaysOnTop -Caption +ToolWindow
  39. Gui, Notes:Color, c000000
  40. Gui, Notes:Font, s18 cFFFFFF
  41. Gui, Notes:Add, Text, x0 y0 h30 w%NoteWidth% Center gAddNote, Add Note
  42. Gui, Notes:Font, s8
  43. Gui, Notes:Add, Text, x0 y33 h13 w%NoteWidth% Center, _________________________________________________________
  44. Gui, Notes:Show, x%NoteLocationX% y0 h%WindowHeight% w%NoteWidth%
  45.  
  46. Gui, NoteList:Show
  47.  
  48. ;;;;;; Put the notes from the active tab (app defaults to first tab) into Note window
  49. BuildNotes(1)
  50.  
  51. ;;;;;;;; TabsGuiContextMenu
  52. Menu, TabMenu, Add, Rename, EditTabName
  53. Menu, TabMenu, Add
  54. Menu, TabMenu, Add, Delete, DeleteTab
  55.  
  56. ;;;;;;;; NotesGuiContextMenu
  57. Menu, NoteListMenu, Add, Edit, EditNote
  58. Menu, NoteListMenu, Add
  59. Menu, NoteListMenu, Add, Delete, DeleteNote
  60. return
  61.  
  62. AddTab:
  63.     InputBox, NewTab, New Tab Name, What would you like to name your new tab?, , 290, 125
  64.     if ErrorLevel
  65.         return
  66.     iniNum := TabNumber ? TabNumber + 1 : 1
  67.     IniWrite, %NewTab%, %Ini%, tabs, %iniNum%
  68.     Gui, Tabs:Destroy
  69.    
  70.     IfNotExist, Tab%iniNum%
  71.         FileCreateDir, Tab%iniNum%
  72.    
  73.     Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow
  74.     Gui, Tabs:Color, cc0c0c0
  75.     Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, +
  76.     GetTabs()
  77.     BuildTabs()
  78.     Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
  79.     WinSet, TransColor, c0c0c0, Tabs
  80.    
  81.     if AutoSwitchToNewTab
  82.         BuildNotes(iniNum)
  83. return
  84.  
  85. AddNote:
  86.     Gui, WriteNote:+AlwaysOnTop
  87.     Gui, WriteNote:Add, Edit, x10 y0 w300 h300 vNoteText,
  88.     Gui, WriteNote:Add, Button, x10 y310 h30 w300 Center gAddNoteFile, Add Note
  89.     Gui, WriteNote:Show, h340 w320, Note Editor
  90. return
  91.  
  92. AddNoteFile:
  93.     GuiControlGet, NoteText, WriteNote:, , Text
  94.     Gui, WriteNote:Destroy
  95.     thisNoteNum := NotesNum + 1
  96.     FileAppend, %NoteText%, Tab%ActiveTab%\note%thisNoteNum%.txt
  97.     Gui, NoteList:Destroy
  98.     BuildNotes(ActiveTab)
  99. return
  100.  
  101. EditNote:
  102.     StringTrimLeft, nNum, noteMenuClicked, 4
  103.  
  104.     FileRead, note, Tab%ActiveTab%\note%nNum%.txt
  105.  
  106.     Gui, EditNote:+AlwaysOnTop
  107.     Gui, EditNote:Add, Edit, x10 y0 w300 h300 vNoteText, % note
  108.     Gui, EditNote:Add, Button, x10 y310 h30 w300 Center gEditNoteFile, Save Note
  109.     Gui, EditNote:Show, h340 w330, Note Editor
  110. return
  111.  
  112. EditNoteFile:
  113.     StringTrimLeft, nNum, noteMenuClicked, 4
  114.  
  115.     GuiControlGet, NoteText, EditNote:, , Text
  116.     Gui, EditNote:Destroy
  117.     FileDelete, Tab%ActiveTab%\note%nNum%.txt
  118.     FileAppend, %NoteText%, Tab%ActiveTab%\note%nNum%.txt
  119.     Gui, NoteList:Destroy
  120.     BuildNotes(ActiveTab)
  121. return
  122.  
  123. DeleteNote:
  124.     StringTrimLeft, nNum, noteMenuClicked, 4
  125.  
  126.     MsgBox, 20, Note Deletion Warning!, Are you sure you want to delete this note?
  127.     IfMsgBox, No
  128.         return
  129.    
  130.     FileDelete, Tab%ActiveTab%\note%nNum%.txt
  131.     if (nNum < NotesNum) {
  132.         loopVar := NotesNum - nNum
  133.         Loop, % loopVar
  134.         {
  135.             startNote := nNum + A_Index
  136.             endNote := startNote - 1
  137.             FileMove, Tab%ActiveTab%\note%startNote%.txt, Tab%ActiveTab%\note%endNote%.txt
  138.         }
  139.     }
  140.    
  141.     NotesNum--
  142.    
  143.     Gui, NotesList:Destroy
  144.    
  145.     BuildNotes(ActiveTab)
  146. return
  147.  
  148. EditTabName:
  149.     StringTrimLeft, tNum, tabMenuClicked, 3
  150.     InputBox, tN, Rename Tab, What would you like to rename your tab?, , 290, 125
  151.     if ErrorLevel
  152.         return
  153.     IniWrite, %tN%, %Ini%, tabs, %tNum%
  154.  
  155.     ; Due to auto-height, I have to destroy and recreate the tabs, otherwise just changing the text on the tab looks silly,
  156.     ; if it's not the same length as the previous text
  157.     Gui, Tabs:Destroy
  158.    
  159.     Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow
  160.     Gui, Tabs:Color, cc0c0c0
  161.     Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, +
  162.     GetTabs()
  163.     BuildTabs()
  164.     Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
  165.     WinSet, TransColor, c0c0c0, Tabs
  166. return
  167.  
  168. DeleteTab:
  169.     StringTrimLeft, tNum, tabMenuClicked, 3
  170.     GuiControlGet, tN, Tabs:, %tabMenuClicked%
  171.     tabsNum := 0
  172.     Loop, Files, Tab%tNum%\*.*
  173.         tabsNum++
  174.     if (tabsNum > 0)
  175.     {
  176.         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?
  177.         IfMsgBox, No
  178.             return
  179.     }
  180.    
  181.     FileRemoveDir, Tab%tNum%, 1
  182.     ; Because of the way the tabs are created, all subsequent folders and ini entries need to be adjusted
  183.     ; to account for the loss of a number... for instance, if there are 6 tabs, and you delete #4,
  184.     ; 5 and 6 need to be redefined as 4 and 5 respectively
  185.     if (tNum < TabNumber) {
  186.         loopVar := TabNumber - tNum
  187.         Loop, % loopVar
  188.         {
  189.             startDir := tNum + A_Index
  190.             endDir := startDir - 1
  191.             FileMoveDir, Tab%startDir%, Tab%endDir%, R
  192.             iniRead, tmp, %Ini%, tabs, %startDir%
  193.             iniWrite, %tmp%, %Ini%, tabs, %endDir%
  194.         }
  195.     }
  196.    
  197.     iniDelete, %Ini%, tabs, %tabNumber%
  198.     tabNumber--
  199.    
  200.     Gui, Tabs:Destroy
  201.  
  202.     Gui, Tabs:+AlwaysOnTop -Caption +ToolWindow
  203.     Gui, Tabs:Color, cc0c0c0
  204.     Gui, Tabs:Add, Button, x0 y0 w%TabWidth% vAddTab gAddTab, +
  205.     GetTabs()
  206.     BuildTabs()
  207.     Gui, Tabs:Show, x%TabLocationX% y0 w%TabWidth%, Tabs
  208.     WinSet, TransColor, c0c0c0, Tabs
  209. return
  210.  
  211. TabPress:
  212.     StringTrimLeft, tabNum, A_GuiControl, 3
  213.     BuildNotes(tabNum)
  214. return
  215.  
  216. GetTabs()
  217. {
  218.     IniRead, Tabs, %Ini%, tabs
  219.  
  220.     global TabList := []
  221.     Loop, Parse, Tabs, `n
  222.     {
  223.         val := A_LoopField
  224.         t := RegExMatch(val, "=") + 2
  225.         val := SubStr(val, t, -1)
  226.         TabList.Insert(val)
  227.     }
  228.  
  229.     global TabNumber := TabList.MaxIndex()
  230. }
  231.  
  232. BuildTabs()
  233. {
  234.     global
  235.     Loop, % TabNumber
  236.     {
  237.         index := A_Index
  238.         IniRead, TabName, %IniLoc%\tabs.ini, tabs, %index%
  239.         TabName := ConvertTabName(TabName)
  240.         if (A_Index = 1)
  241.             Gui, Tabs:Add, Button, x0 y30 w%TabWidth% vTab%index% gTabPress, % TabName
  242.         else
  243.             Gui, Tabs:Add, Button, x0 w%TabWidth% vTab%index% gTabPress, % TabName
  244.     }
  245. }
  246.  
  247. BuildNotes(tn)
  248. {
  249.     global
  250.     ActivateTab(tn)
  251.     notesNum := 0
  252.     Loop, Files, Tab%ActiveTab%\*.*
  253.         notesNum++
  254.     NotesNum := notesNum ? notesNum : 0
  255.  
  256.     Gui, NoteList:Destroy
  257.        
  258.     Gui, NoteList:+AlwaysOnTop +OwnerNotes -Caption +ToolWindow
  259.     Gui, NoteList:Color, c000000
  260.     Gui, NoteList:Font, s10 cFFFFFF
  261.     thisWidth := NoteWidth - 10
  262.     Loop, % NotesNum
  263.     {
  264.         FileRead, note, Tab%ActiveTab%\note%A_Index%.txt
  265.         Gui, NoteList:Add, Text, x5 w%thisWidth% vNote%A_Index% Center, % note "`n_______________________________"
  266.        
  267.     }
  268.     Gui, NoteList:Show, x%NoteLocationX% y50 w%NoteWidth%,
  269. }
  270.  
  271. ActivateTab(tn)
  272. {
  273.     Gui, Tabs:Font,
  274.     GuiControl, Tabs:Font, Tab%ActiveTab%
  275.     Gui, Tabs:Font, Bold
  276.     GuiControl, Tabs:Font, Tab%tn%
  277.     GuiControl, Tabs:Enable, Tab%ActiveTab%
  278.     GuiControl, Tabs:Disable, Tab%tn%
  279.     ActiveTab := tn
  280. }
  281.  
  282. ConvertTabName(name)
  283. {
  284.     newName =
  285.     Loop, Parse, name
  286.     {
  287.         newName .= A_Index < StrLen(name) ? A_LoopField "`n" : A_LoopField
  288.     }
  289.     return newName
  290. }
  291.        
  292. TabsGuiContextMenu:
  293. tabMenuClicked := A_GuiControl
  294. if !A_GuiControl
  295.     return
  296. Menu, TabMenu, Show
  297. return
  298.  
  299. NoteListGuiContextMenu:
  300. if !A_GuiControl
  301.     return
  302. noteMenuClicked := A_GuiControl
  303. Menu, NoteListMenu, Show
  304. return
  305.  
  306. F11::
  307. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement