Skip to content

Commit

Permalink
Add Travis CI support and fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Jun 12, 2015
1 parent fcfd6d3 commit 9f8f6c5
Show file tree
Hide file tree
Showing 16 changed files with 500 additions and 59 deletions.
15 changes: 15 additions & 0 deletions .prospector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
strictness: medium
doc-warnings: true
test-warnings: false
max-line-length: 120
ignore-patterns:
- docs
- docs_theme
dodgy:
run: false
pep257:
disable:
- D202
pylint:
disable:
- import-error
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
python:
- "3.3"
install:
- pip install flake8
- pip install flake8_docstrings
- pip install pep8-naming
- pip install nose
script:
- nosetests .
- flake8 .
73 changes: 64 additions & 9 deletions favorite_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Favorite Files
Favorite Files.
Licensed under MIT
Copyright (c) 2012 Isaac Muse <isaacmuse@gmail.com>
Copyright (c) 2012 - 2015 Isaac Muse <isaacmuse@gmail.com>
"""

import sublime
Expand All @@ -14,18 +15,28 @@


class CleanOrphanedFavoritesCommand(sublime_plugin.WindowCommand):

"""Clean out favorties that no longer exist."""

def run(self):
"""Run the command."""

# Clean out all dead links
if not Favs.load(clean=True, win_id=self.window.id()):
Favs.load(force=True, clean=True, win_id=self.window.id())


class SelectFavoriteFileCommand(sublime_plugin.WindowCommand):

"""Open the selected favorite(s)."""

def open_file(self, value, group=False):
"""Open the file(s)."""

if value >= 0:
active_group = self.window.active_group()
if value < self.num_files or (group and value < self.num_files + 1):
# Open global file, file in group, or all fiels in group
# Open global file, file in group, or all files in group
names = []
if group:
if value == 0:
Expand Down Expand Up @@ -53,7 +64,8 @@ def open_file(self, value, group=False):
error("The following file does not exist:\n%s" % n)
if focus_view is not None:
# Horrible ugly hack to ensure opened file gets focus
def fn(v):
def fn(focus_view):
"""Ensure focus of view."""
self.window.focus_view(focus_view)
self.window.show_quick_panel(["None"], None)
self.window.run_command("hide_overlay")
Expand All @@ -76,6 +88,8 @@ def fn(v):
error("No favorites found! Try adding some.")

def run(self):
"""Run the command."""

if not Favs.load(win_id=self.window.id()):
self.files = Favs.all_files()
self.num_files = len(self.files)
Expand All @@ -91,7 +105,12 @@ def run(self):


class AddFavoriteFileCommand(sublime_plugin.WindowCommand):

"""Add favorite(s) to the global group or the specified group."""

def add(self, names, group_name=None):
"""Add favorites."""

disk_omit_count = 0
added = 0
# Iterate names and add them to group/global if not already added
Expand All @@ -108,10 +127,15 @@ def add(self, names, group_name=None):
Favs.save(True)
if disk_omit_count:
# Alert that files could be added
message = "1 file does not exist on disk!" if disk_omit_count == 1 else "%d file(s) do not exist on disk!" % disk_omit_count
if disk_omit_count == 1:
message = "1 file does not exist on disk!"
else:
message = "%d file(s) do not exist on disk!" % disk_omit_count
error(message)

def create_group(self, value):
"""Create the specified group."""

repeat = False
if value == "":
# Require an actual name
Expand All @@ -137,6 +161,8 @@ def create_group(self, value):
v.run_command("select_all")

def select_group(self, value, replace=False):
"""Add favorite to the group."""

if value >= 0:
group_name = self.groups[value][0].replace("Group: ", "", 1)
if replace:
Expand All @@ -146,6 +172,8 @@ def select_group(self, value, replace=False):
self.add(self.name, group_name)

def show_groups(self, replace=False):
"""Prompt user with stored groups."""

# Show availabe groups
self.groups = Favs.all_groups()
self.window.show_quick_panel(
Expand All @@ -154,6 +182,8 @@ def show_groups(self, replace=False):
)

def group_answer(self, value):
"""Handle the user's 'group' options answer."""

if value >= 0:
if value == 0:
# No group; add file to favorites
Expand All @@ -175,7 +205,9 @@ def group_answer(self, value):
# "Replace Group"
self.show_groups(replace=True)

def group_prompt(self, first=False):
def group_prompt(self):
"""Prompt user with 'group' options."""

# Default options
self.group = ["No Group", "Create Group"]
if Favs.group_count() > 0:
Expand All @@ -188,6 +220,8 @@ def group_prompt(self, first=False):
)

def file_answer(self, value):
"""Handle the user's 'add' option selection."""

if value >= 0:
view = self.window.active_view()
if view is not None:
Expand All @@ -209,7 +243,7 @@ def file_answer(self, value):
self.group_prompt()
if value == 2:
# All files in layout group
group, idx = self.window.get_view_index(view)
group = self.window.get_view_index(view)[0]
views = self.window.views_in_group(group)
if len(views) > 0:
for v in views:
Expand All @@ -220,6 +254,8 @@ def file_answer(self, value):
self.group_prompt()

def file_prompt(self, view_code):
"""Prompt the user for 'add' options."""

# Add current active file
options = ["Add Current File to Favorites"]
if view_code > 0:
Expand All @@ -236,6 +272,8 @@ def file_prompt(self, view_code):
)

def run(self):
"""Run the command."""

view = self.window.active_view()
self.name = []

Expand All @@ -249,7 +287,7 @@ def run(self):
view_code = 1
# See if there is more than one group; if so allow saving of a specific group
if self.window.num_groups() > 1:
group, idx = self.window.get_view_index(view)
group = self.window.get_view_index(view)[0]
group_views = self.window.views_in_group(group)
if len(group_views) > 1:
view_code = 2
Expand All @@ -259,11 +297,16 @@ def run(self):
name = view.file_name()
if name is not None:
self.name.append(name)
self.group_prompt(True)
self.group_prompt()


class RemoveFavoriteFileCommand(sublime_plugin.WindowCommand):

"""Remove the file favorites from the tracked list."""

def remove(self, value, group=False, group_name=None):
"""Remove the favorite(s)."""

if value >= 0:
# Remove file from global, file from group list, or entire group
if value < self.num_files or (group and value < self.num_files + 1):
Expand Down Expand Up @@ -304,6 +347,8 @@ def remove(self, value, group=False, group_name=None):
error("No favorites found! Try adding some.")

def run(self):
"""Run the command."""

if not Favs.load(win_id=self.window.id()):
# Present both files and groups for removal
self.files = Favs.all_files()
Expand All @@ -322,7 +367,11 @@ def run(self):


class TogglePerProjectFavoritesCommand(sublime_plugin.WindowCommand):

"""Toggle per project favorites."""

def run(self):
"""Run the command."""
win_id = self.window.id()

# Try and toggle back to global first
Expand All @@ -336,17 +385,23 @@ def run(self):
Favs.open(win_id=self.window.id())

def is_enabled(self):
"""Check if command is enabled."""

return sublime.load_settings("favorite_files.sublime-settings").get("enable_per_projects", False)


def check_st_version():
"""Check the Sublime version."""

if int(sublime.version()) < 3080:
window = sublime.active_window()
if window is not None:
window.run_command('open_file', {"file": "${packages}/FavoriteFiles/messages/upgrade-st-3080.md"})


def plugin_loaded():
"""Setup plugin."""

global Favs
Favs = Favorites(join(sublime.packages_path(), 'User', 'favorite_files_list.json'))
check_st_version()
2 changes: 1 addition & 1 deletion favorite_files.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// Enable ability for per project favorites .
// Per Projets must be toggled on for each project you are in.
// Per Projects must be toggled on for each project you are in.
// You can toggle back and forth between per project and global favorites.
"enable_per_projects": true,

Expand Down
Loading

0 comments on commit 9f8f6c5

Please sign in to comment.