diff --git a/const.pb b/const.pb index 17043ca..e355b39 100644 --- a/const.pb +++ b/const.pb @@ -33,6 +33,12 @@ Enumeration main #menuPrefs #menuUpdateCheck #menuAbout + #columnMenu + #columnMenuShortcut + #columnMenuAction + #columnMenuCommand + #columnMenuWorkdir + #columnMenuReset #menuCustom EndEnumeration diff --git a/helpers.pb b/helpers.pb index 94b51b1..6f723fe 100644 --- a/helpers.pb +++ b/helpers.pb @@ -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 \ No newline at end of file diff --git a/main.pb b/main.pb index 75d272e..613efb0 100644 --- a/main.pb +++ b/main.pb @@ -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)) @@ -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,"") @@ -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 @@ -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 @@ -375,6 +422,7 @@ Repeat viewingMode() EndIf wndState(#hide) + settings(#True) Case #evDisableShortcut,#evEnableShortcut,#evToggleShortcut If EventData() Define shortcut.s = PeekS(EventData()) diff --git a/proc.pb b/proc.pb index e2d9777..90724af 100644 --- a/proc.pb +++ b/proc.pb @@ -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) @@ -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)