Advertisement
Guest User

Untitled

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