Skip to content

Commit

Permalink
fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
deseven committed Oct 25, 2020
1 parent 9b90d18 commit f1a95c4
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
6 changes: 6 additions & 0 deletions const.pb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Enumeration main
#menuPrefs
#menuUpdateCheck
#menuAbout
#columnMenu
#columnMenuShortcut
#columnMenuAction
#columnMenuCommand
#columnMenuWorkdir
#columnMenuReset
#menuCustom
EndEnumeration

Expand Down
31 changes: 31 additions & 0 deletions helpers.pb
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,35 @@ Macro deactivateSelector(hotkey = "")
activeSelector = -1
previousHotkey = ""
EndIf
EndMacro

Macro setColumnsState()
If GetMenuItemState(#columnMenu,#columnMenuShortcut)
ListIconGadgetHideColumn(#gadShortcuts,2,#False)
Else
ListIconGadgetHideColumn(#gadShortcuts,2,#True)
EndIf
If GetMenuItemState(#columnMenu,#columnMenuAction)
ListIconGadgetHideColumn(#gadShortcuts,3,#False)
Else
ListIconGadgetHideColumn(#gadShortcuts,3,#True)
EndIf
If GetMenuItemState(#columnMenu,#columnMenuCommand)
ListIconGadgetHideColumn(#gadShortcuts,4,#False)
Else
ListIconGadgetHideColumn(#gadShortcuts,4,#True)
EndIf
If GetMenuItemState(#columnMenu,#columnMenuWorkdir)
ListIconGadgetHideColumn(#gadShortcuts,5,#False)
Else
ListIconGadgetHideColumn(#gadShortcuts,5,#True)
EndIf
EndMacro

Macro ToggleMenuItemState(Menu,MenuItem)
If GetMenuItemState(Menu,MenuItem)
SetMenuItemState(Menu,MenuItem,#False)
Else
SetMenuItemState(Menu,MenuItem,#True)
EndIf
EndMacro
52 changes: 50 additions & 2 deletions main.pb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ CocoaMessage(0,GadgetID(#gadShortcuts),"setFocusRingType:",1)
AddGadgetColumn(#gadShortcuts,2,"Action",120)
AddGadgetColumn(#gadShortcuts,3,"Command",1)
AddGadgetColumn(#gadShortcuts,4,"Workdir",1)
ListIconGadgetHideColumn(#gadShortcuts,4,#True)
ListIconGadgetHideColumn(#gadShortcuts,0,#True)
CocoaMessage(0,GadgetID(#gadShortcuts),"sizeLastColumnToFit")
ButtonImageGadget(#gadAdd,460,222,36,34,ImageID(#resAdd))
ButtonImageGadget(#gadEdit,496,222,36,34,ImageID(#resEdit))
ButtonImageGadget(#gadDel,532,222,36,34,ImageID(#resDel))
Expand All @@ -68,6 +66,14 @@ CocoaMessage(0,GadgetID(#gadCancel),"setBordered:",0)
CocoaMessage(0,GadgetID(#gadUp),"setBordered:",0)
CocoaMessage(0,GadgetID(#gadDown),"setBordered:",0)

CreatePopupMenu(#columnMenu)
MenuItem(#columnMenuShortcut,"Shortcut")
MenuItem(#columnMenuAction,"Action")
MenuItem(#columnMenuCommand,"Command")
MenuItem(#columnMenuWorkdir,"Workdir")
MenuBar()
MenuItem(#columnMenuReset,"Reset")

AddGadgetItem(#gadTabs,1,"Preferences")
TextGadget(#gadPrefShellCap,10,12,45,20,"Shell:")
StringGadget(#gadPrefShell,55,10,210,20,"")
Expand Down Expand Up @@ -134,11 +140,18 @@ registerShortcuts()

;If #True
If Not CountGadgetItems(#gadShortcuts)
; a hack to add a special gadget state column
AddGadgetItem(#gadShortcuts,0,~"-\n-\n-\n-")
SetGadgetItemState(#gadShortcuts,0,#PB_ListIcon_Checked)
SetGadgetItemImage(#gadShortcuts,i,ImageID(#resDisabled))
ClearGadgetItems(#gadShortcuts)
wndState(#show)
Else
wndState(#hide)
EndIf

setColumnsState()

WindowBounds(#wnd,600,300,1280,720)
BindEvent(#PB_Event_SizeWindow,@windowHandler())
If wndX = #PB_Ignore
Expand Down Expand Up @@ -168,6 +181,40 @@ Repeat
wndY = WindowY(#wnd)
settings(#True)
EndIf
Case #PB_Event_RightClick
If GetGadgetState(#gadTabs) = 0
If (WindowMouseX(#wnd) >= GadgetX(#gadShortcuts)) And (WindowMouseX(#wnd) <= GadgetX(#gadShortcuts) + GadgetWidth(#gadShortcuts)) And
(WindowMouseY(#wnd) >= GadgetY(#gadShortcuts)) And (WindowMouseY(#wnd) <= GadgetY(#gadShortcuts) + GadgetHeight(#gadShortcuts))
DisplayPopupMenu(#columnMenu,WindowID(#wnd))
EndIf
EndIf
Case #PB_Event_Menu
Select EventMenu()
Case #columnMenuShortcut
ToggleMenuItemState(#columnMenu,#columnMenuShortcut)
Case #columnMenuAction
ToggleMenuItemState(#columnMenu,#columnMenuAction)
Case #columnMenuCommand
ToggleMenuItemState(#columnMenu,#columnMenuCommand)
Case #columnMenuWorkdir
ToggleMenuItemState(#columnMenu,#columnMenuWorkdir)
Case #columnMenuReset
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,80,0)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,100,1)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,120,2)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,100,3)
SetMenuItemState(#columnMenu,#columnMenuShortcut,#True)
SetMenuItemState(#columnMenu,#columnMenuAction,#True)
SetMenuItemState(#columnMenu,#columnMenuCommand,#True)
SetMenuItemState(#columnMenu,#columnMenuWorkdir,#False)
setColumnsState()
CocoaMessage(0,GadgetID(#gadShortcuts),"sizeLastColumnToFit")
settings(#True)
EndSelect
If EventMenu() >= #columnMenuShortcut And EventMenu() <= #columnMenuWorkdir
setColumnsState()
settings(#True)
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case #gadShortcuts
Expand Down Expand Up @@ -375,6 +422,7 @@ Repeat
viewingMode()
EndIf
wndState(#hide)
settings(#True)
Case #evDisableShortcut,#evEnableShortcut,#evToggleShortcut
If EventData()
Define shortcut.s = PeekS(EventData())
Expand Down
48 changes: 48 additions & 0 deletions proc.pb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ Procedure settings(save.b = #False)
WritePreferenceInteger("window_y",wndY)
WritePreferenceInteger("window_width",wndW)
WritePreferenceInteger("window_height",wndH)
If GetMenuItemState(#columnMenu,#columnMenuShortcut)
WritePreferenceString("shortcut_column_enabled","yes")
Else
WritePreferenceString("shortcut_column_enabled","no")
EndIf
If GetMenuItemState(#columnMenu,#columnMenuAction)
WritePreferenceString("action_column_enabled","yes")
Else
WritePreferenceString("action_column_enabled","no")
EndIf
If GetMenuItemState(#columnMenu,#columnMenuCommand)
WritePreferenceString("command_column_enabled","yes")
Else
WritePreferenceString("command_column_enabled","no")
EndIf
If GetMenuItemState(#columnMenu,#columnMenuWorkdir)
WritePreferenceString("workdir_column_enabled","yes")
Else
WritePreferenceString("workdir_column_enabled","no")
EndIf
WritePreferenceInteger("shortcut_column_width",GetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,0))
WritePreferenceInteger("action_column_width",GetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,1))
WritePreferenceInteger("command_column_width",GetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,2))
WritePreferenceInteger("workdir_column_width",GetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,3))
For i = 0 To CountGadgetItems(#gadShortcuts)-1
shortcut = GetGadgetItemText(#gadShortcuts,i,0)
action = GetGadgetItemText(#gadShortcuts,i,1)
Expand Down Expand Up @@ -145,6 +169,30 @@ Procedure settings(save.b = #False)
SetGadgetState(#gadPrefSetWorkdirCD,#PB_Checkbox_Unchecked)
setWorkdirWithCD = #False
EndIf
If ReadPreferenceString("shortcut_column_enabled","yes") = "yes"
SetMenuItemState(#columnMenu,#columnMenuShortcut,#True)
Else
SetMenuItemState(#columnMenu,#columnMenuShortcut,#False)
EndIf
If ReadPreferenceString("action_column_enabled","yes") = "yes"
SetMenuItemState(#columnMenu,#columnMenuAction,#True)
Else
SetMenuItemState(#columnMenu,#columnMenuAction,#False)
EndIf
If ReadPreferenceString("command_column_enabled","yes") = "yes"
SetMenuItemState(#columnMenu,#columnMenuCommand,#True)
Else
SetMenuItemState(#columnMenu,#columnMenuCommand,#False)
EndIf
If ReadPreferenceString("workdir_column_enabled","no") = "yes"
SetMenuItemState(#columnMenu,#columnMenuWorkdir,#True)
Else
SetMenuItemState(#columnMenu,#columnMenuWorkdir,#False)
EndIf
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,ReadPreferenceInteger("shortcut_column_width",80),0)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,ReadPreferenceInteger("action_column_width",100),1)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,ReadPreferenceInteger("command_column_width",120),2)
SetGadgetItemAttribute(#gadShortcuts,0,#PB_ListIcon_ColumnWidth,ReadPreferenceInteger("workdir_column_width",100),3)
wndX = ReadPreferenceInteger("window_x",#PB_Ignore)
wndY = ReadPreferenceInteger("window_y",#PB_Ignore)
wndW = ReadPreferenceInteger("window_width",600)
Expand Down

0 comments on commit f1a95c4

Please sign in to comment.