Skip to content

Commit

Permalink
Return to previous screen on rescan
Browse files Browse the repository at this point in the history
- Update icons
- Use path of project folder as copytext and action value
  • Loading branch information
deanishe committed Nov 12, 2021
1 parent 13eef51 commit 2008c94
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 299 deletions.
Binary file added Alfred Sublime Text.afdesign
Binary file not shown.
Binary file removed Alfred-Sublime-Text.afdesign
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Usage
- `.st rescan` — Reload cached list of projects
- `.st config` — Show the current settings
- `Workflow Is Up To Date` / `Workflow Update Available` — Install update or check for update
- `Rescan Projects` — Reload list of projects
- `Edit Config File` — Open workflow's config file in Sublime Text
- `View Help File` — Open README in your browser
- `Report Issue` — Open GitHub issue tracker in your browser
- `Visit Forum Thread` — Open workflow's thread on [alfredforum.com][forum]
- `Rescan Projects` — Reload list of projects

You can enter the words `search` or `config` as a search query anywhere to jump to that screen.

Expand Down
79 changes: 41 additions & 38 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var (
opts = &options{}
cli = flag.NewFlagSet("alfsubl", flag.ContinueOnError)
cli = flag.NewFlagSet("alfred-sublime", flag.ContinueOnError)

// Candidate paths to `subl` command-line program. We'll open projects
// via `subl` because it correctly loads the workspace. Opening a
Expand Down Expand Up @@ -155,7 +155,6 @@ func runOpenFolder() {

// Filter configuration in Alfred
func runConfig() {

// prevent Alfred from re-ordering results
if opts.Query == "" {
wf.Configure(aw.SuppressUIDs(true))
Expand All @@ -181,6 +180,16 @@ func runConfig() {
Icon(iconUpdateOK)
}

wf.NewItem("Rescan Projects").
Subtitle("Rebuild cached list of projects").
Arg("-rescan", "-force").
Valid(true).
UID("rescan").
Icon(iconReload).
// Var("hide_alfred", "false").
Var("notification", "Reloading project list…").
Var("trigger", "config")

wf.NewItem("Edit Config File").
Subtitle("Edit directories to scan").
Valid(true).
Expand Down Expand Up @@ -210,20 +219,9 @@ func runConfig() {
Arg("-open", forumThreadURL).
UID("forum").
Valid(true).
Icon(iconURL).
Icon(iconForum).
Var("hide_alfred", "true")

// TODO: add "back to" setting for rescan command
wf.NewItem("Rescan Projects").
Subtitle("Rebuild cached list of projects").
Arg("-rescan", "-force").
Valid(true).
UID("rescan").
Icon(iconReload).
// Var("hide_alfred", "false").
Var("notification", "Reloading project list…").
Var("trigger", conf.BackToTrigger)

if opts.Query != "" {
wf.Filter(opts.Query)
addNavigationItems(opts.Query, "config", "rescan")
Expand Down Expand Up @@ -296,10 +294,9 @@ func runSearch() {
}

if len(projs) == 0 && wf.IsRunning("rescan") {

wf.Rerun(0.1)
wf.NewItem("Scanning projects…").
Subtitle("Results will refresh in a few seconds").
Subtitle("Results will be available shortly").
Valid(false).
Icon(iconSpinner())

Expand All @@ -313,13 +310,13 @@ func runSearch() {
}

for _, proj := range projs {

it := wf.NewItem(proj.Name()).
Subtitle(util.PrettyPath(proj.Path)).
Valid(true).
Arg("-project", "--", proj.Path).
UID(proj.Path).
IsFile(true).
Copytext(proj.Folder()).
Action(proj.Folder()).
Icon(icon).
Var("hide_alfred", "true")

Expand Down Expand Up @@ -347,10 +344,11 @@ func runSearch() {
wf.SendFeedback()
}

func addNavigationItems(query string, ignore ...string) {
func addNavigationItems(query, backTo string, ignore ...string) {
if len(query) < 3 {
return
}
ignore = append(ignore, backTo)
var (
items = []struct {
keywords []string
Expand All @@ -363,6 +361,9 @@ func addNavigationItems(query string, ignore ...string) {
}{
{
[]string{"reload", "rescan"},
// Trigger doesn't exist, but we can't put the
// real trigger (backTo) here yet because it's
// the current action, which we want to filter out
"rescan",
"Rescan Projects",
"Rescan disk & update cached list of projects",
Expand Down Expand Up @@ -397,28 +398,30 @@ func addNavigationItems(query string, ignore ...string) {
continue
}
for _, kw := range conf.keywords {
if strings.HasPrefix(strings.ToLower(kw), query) {
it := wf.NewItem(conf.title).
Subtitle(conf.subtitle).
Icon(conf.icon).
UID("navigation-action."+conf.trigger).
Valid(true).
Var("trigger", conf.trigger).
Var("query", "")

if conf.trigger == "rescan" {
it.Var("trigger", "search")
}
if !strings.HasPrefix(strings.ToLower(kw), query) {
continue
}
it := wf.NewItem(conf.title).
Subtitle(conf.subtitle).
Icon(conf.icon).
UID("navigation-action."+conf.trigger).
Valid(true).
Var("trigger", conf.trigger).
Var("query", "")

// override non-existent "rescan" trigger
if conf.trigger == "rescan" {
it.Var("trigger", backTo)
}

if conf.arg != nil {
it.Arg(conf.arg...)
}
if conf.arg != nil {
it.Arg(conf.arg...)
}

if conf.note != "" {
it.Var("notification", conf.note)
}
break
if conf.note != "" {
it.Var("notification", conf.note)
}
break
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ const (
// DefaultLocateInterval is how often to run locate
DefaultLocateInterval = 24 * time.Hour

// DefaultBackToTrigger is what trigger is called after a rescan
DefaultBackToTrigger = "config"

defaultConfig = `# How many directories deep to search by default.
# 0 = the directory itself
# 1 = immediate children of the directory
Expand Down Expand Up @@ -86,7 +83,6 @@ func init() {
FindInterval: DefaultFindInterval,
MDFindInterval: DefaultMDFindInterval,
LocateInterval: DefaultLocateInterval,
BackToTrigger: DefaultBackToTrigger,
}
}

Expand All @@ -96,7 +92,6 @@ type config struct {
MDFindInterval time.Duration `toml:"-"`
LocateInterval time.Duration `toml:"-"`
VSCode bool `toml:"-" env:"VSCODE"`
BackToTrigger string `toml:"-"`

// From config file
Excludes []string `toml:"excludes"`
Expand Down Expand Up @@ -140,15 +135,10 @@ func loadConfig(path string) (*config, error) {
return nil, err
}

// Update depths
// Update depths and expand paths
if conf.Depth == 0 {
conf.Depth = DefaultDepth
}

if conf.BackToTrigger != "config" && conf.BackToTrigger != "search" {
conf.BackToTrigger = "config"
}

for _, sp := range conf.SearchPaths {
if sp.Depth == 0 {
sp.Depth = conf.Depth
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/deanishe/alfred-sublime-text

go 1.13

require (
github.com/BurntSushi/toml v0.3.1
github.com/davecgh/go-spew v1.1.1
Expand All @@ -9,4 +11,3 @@ require (
github.com/yosuke-furukawa/json5 v0.1.1
)

go 1.13
1 change: 0 additions & 1 deletion icon.png

This file was deleted.

Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 6 additions & 8 deletions icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ import (

// Workflow icons
var (
iconError = &aw.Icon{Value: "icons/error.png"}
iconForum = &aw.Icon{Value: "icons/forum.png"}
iconHelp = &aw.Icon{Value: "icons/help.png"}
iconIssue = &aw.Icon{Value: "icons/issue.png"}
iconReload = &aw.Icon{Value: "icons/reload.png"}
iconSettings = &aw.Icon{Value: "icons/settings.png"}
iconURL = &aw.Icon{Value: "icons/url.png"}
iconSublime = &aw.Icon{Value: "icons/sublime.png"}
iconUpdateAvailable = &aw.Icon{Value: "icons/update-available.png"}
iconUpdateOK = &aw.Icon{Value: "icons/update-ok.png"}
iconWarning = &aw.Icon{Value: "icons/warning.png"}
iconSublime = &aw.Icon{Value: "icons/sublime.png"}
iconVSCode = &aw.Icon{Value: "icons/vscode.png"}
// iconDocs = &aw.Icon{Value: "icons/docs.png"}
// iconOff = &aw.Icon{Value: "icons/off.png"}
// iconOn = &aw.Icon{Value: "icons/on.png"}
// iconTrash = &aw.Icon{Value: "icons/trash.png"}
spinnerIcons = []*aw.Icon{
iconWarning = &aw.Icon{Value: "icons/warning.png"}
spinnerIcons = []*aw.Icon{
{Value: "icons/spinner-1.png"},
{Value: "icons/spinner-2.png"},
{Value: "icons/spinner-3.png"},
}
)

func init() {
aw.IconError = iconError
aw.IconWarning = iconWarning
}

Expand Down
Binary file removed icons/docs.png
Binary file not shown.
Binary file added icons/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/forum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/icon.png
Binary file not shown.
Binary file modified icons/issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/log.png
Binary file not shown.
Binary file removed icons/off.png
Binary file not shown.
Binary file removed icons/on.png
Binary file not shown.
Binary file modified icons/reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/reset.png
Binary file not shown.
Binary file modified icons/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/spinner-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/spinner-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/spinner-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/sublime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/update-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/update-ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/url.png
Binary file not shown.
Binary file modified icons/vscode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icons/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2008c94

Please sign in to comment.