Skip to content

Commit

Permalink
Add custom behavior in file mode to select files
Browse files Browse the repository at this point in the history
  • Loading branch information
andweeb committed Feb 3, 2019
1 parent 81bd3ac commit d52d051
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/html/Entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ <h5><a href="#dispatchAction">dispatchAction</a></h5>
<ul>
<li><code>mode</code> - The name of the current mode</li>
<li><code>shortcut</code> - A shortcut object containing the keybindings and event handler for the entity</li>
<li><code>workflow</code> - The list of events that compose the current workflow</li>
</ul>
<p>Returns:</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown/Entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Entity class that represents some generic automatable desktop entity
| **Signature** | `Entity:dispatchAction(mode, shortcut) -> boolean` |
| **Type** | Method |
| **Description** | Dispatch an action from a shortcut within the context of the given mode |
| **Parameters** | <ul><li>`mode` - The name of the current mode</li><li>`shortcut` - A shortcut object containing the keybindings and event handler for the entity</li></ul> |
| **Parameters** | <ul><li>`mode` - The name of the current mode</li><li>`shortcut` - A shortcut object containing the keybindings and event handler for the entity</li><li>`workflow` - The list of events that compose the current workflow</li></ul> |
| **Returns** | <ul><li>A boolean denoting to whether enable or disable automatic mode exit after the action has been dispatched</li></ul> |

| [getEventHandler](#getEventHandler) | |
Expand Down
25 changes: 23 additions & 2 deletions src/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ File.behaviors = Entity.behaviors + {
eventHandler(self.path)
return true
end,
file = function(self, eventHandler, _, _, workflow)
local shouldNavigate = false

for _, event in pairs(workflow) do
if event.mode == "select" then
shouldNavigate = true
break
end
end

eventHandler(self.path, shouldNavigate)

return true
end,
}

--- File:initialize(path, shortcuts)
Expand All @@ -57,17 +71,24 @@ function File:initialize(path, shortcuts)
local absolutePath = hs.fs.pathToAbsolute(path)
local attributes = hs.fs.attributes(absolutePath) or {}
local isDirectory = attributes.mode == "directory"
local openFileInFolder = self:createEvent(path, function(target) self.open(target) end)

local actions = {
open = self.open,
copy = function(target) self:copy(target) end,
move = function(target) self:move(target) end,
showCheatsheet = function() self.cheatsheet:show() end,
openFileInFolder = self:createEvent(path, function(target) self.open(target) end),
openFileInFolder = openFileInFolder,
openFileInFolderWith = self:createEvent(path, function(target) self:openWith(target) end),
showInfoForFileInFolder = self:createEvent(path, function(target) self:openInfoWindow(target) end),
quickLookFileInFolder = self:createEvent(path, function(target) hs.execute("qlmanage -p "..target) end),
deleteFileInFolder = self:createEvent(path, function(target) self:moveToTrash(target) end),
open = function(target, shouldNavigate)
if shouldNavigate then
return openFileInFolder(target)
end

return self.open(target)
end,
}
local commonShortcuts = {
{ nil, nil, actions.open, { path, "Activate/Focus" } },
Expand Down
6 changes: 6 additions & 0 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ Ki.defaultTransitionEvents = {
function() Ki.state:exitMode() end,
{ "Select Mode", "Exit to Normal Mode" },
},
{
{"cmd"}, "f",
function() Ki.state:enterFileMode() end,
{ "Select Mode", "Transition to File Mode" },
},
},
url = {
{
Expand Down Expand Up @@ -378,6 +383,7 @@ Ki._defaultStateEvents = {
{ name = "enterSelectMode", from = "normal", to = "select" },
{ name = "enterFileMode", from = "normal", to = "file" },
{ name = "enterFileMode", from = "entity", to = "file" },
{ name = "enterFileMode", from = "select", to = "file" },
{ name = "enterSelectMode", from = "file", to = "select" },
{ name = "enterVolumeControlMode", from = "normal", to = "volume" },
{ name = "enterBrightnessControlMode", from = "normal", to = "brightness" },
Expand Down

0 comments on commit d52d051

Please sign in to comment.