Skip to content

Commit

Permalink
Added top level class. added key bindings, added context menu, added …
Browse files Browse the repository at this point in the history
…metadata, packages, changelog and messages
  • Loading branch information
hgraca committed Apr 21, 2013
1 parent 2bdaebb commit 15c7c5e
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 48 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0.0
=====
* Initial Version
29 changes: 29 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
New BSD License
===============

Copyright (c) 2012, Stuart Herbert and contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@

## Usefull command lines

ln -s ${PWD} ~/.config/sublime-text-2/Packages/PhpRefactor
ln -s ${PWD} ~/.config/sublime-text-2/Packages/PhpRefactor

## Usefull sublime console lines

view.run_command('extract', {'execute': False})
view.run_command('extract', {'execute': True})
Binary file modified lib/refactor.phar
Binary file not shown.
Binary file added lib/refactor.phar.old
Binary file not shown.
4 changes: 4 additions & 0 deletions messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"install": "messages/install.md",
"1.0.0": "messages/1.0.0.md"
}
14 changes: 14 additions & 0 deletions messages/1.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

New on 1.0.0
============

* extract function is working from the keyboard shortcut
* Use view.run_command('extract', {'execute': False}) for the resulting diff
* Use view.run_command('extract', {'execute': True}) to compute and apply the extraction


If you have any questions or found a bug fell free to contact me at [email protected]

For bugs open an issue on github https://github.com/hgraca/sublime-text-2-php-refactor/issues

Hope you enjoy it.
8 changes: 8 additions & 0 deletions messages/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

Thank you for installing sublime-text-2-php-refactor.

If you have any questions or found a bug fell free to contact me at [email protected]

For bugs open an issue on github https://github.com/hgraca/sublime-text-2-php-refactor/issues

Hope you enjoy it.
5 changes: 5 additions & 0 deletions package-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"url": "https://github.com/hgraca/sublime-text-2-php-refactor",
"version": "1.0.0",
"description": "Refactoring for php classes"
}
20 changes: 20 additions & 0 deletions packages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"schema_version": "1.2",
"packages": [
{
"name": "Sublime Text 2 PHP Refactor",
"description": "Refactoring for php classes",
"author": "Herberto Graça",
"homepage": "https://github.com/hgraca/sublime-text-2-php-refactor",
"last_modified": "2013-03-18 09:43:00",
"platforms": {
"*": [
{
"version": "1.0.0",
"url": "https://github.com/hgraca/sublime-text-2-php-refactor/archive/1.0.0.zip"
}
]
}
}
]
}
2 changes: 2 additions & 0 deletions sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Calculator
{

public $test = 0;
public function calculate($a, $b, $op)
{
if ($op == '+'){
Expand Down
12 changes: 0 additions & 12 deletions sandbox_bkp.php

This file was deleted.

75 changes: 40 additions & 35 deletions sublime-text-2-php-refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@
from os.path import dirname, realpath, basename


'''
Top level class for the plugin commands
'''


class Refactor():
REFACTOR = sublime.packages_path() + "/sublime-text-2-php-refactor/lib/refactor.phar"

def execute(self, name, command, execute=False):
fileName = basename(self.view.file_name())

print 'Executing: ' + name + ' (' + command + ')'

p = subprocess.Popen(command, cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
if p.stdout is not None:
msg = p.stdout.readlines()
msg = '\n'.join(msg)
if (False == execute):
outputWindow = self.getOutputWindow(name + '_' + fileName + '.diff')
edit = outputWindow.begin_edit()
outputWindow.insert(edit, 0, msg)
outputWindow.end_edit(edit)
outputWindow.set_read_only(True)
else:
print msg

def getOutputWindow(self, windowName, sintax='Diff'):
outputWindow = sublime.active_window().new_file()
outputWindow.set_name(windowName)
outputWindow.set_syntax_file('Packages/' + sintax + '/' + sintax + '.tmLanguage')
outputWindow.set_read_only(False)

return outputWindow


'''
Extract a range of lines into a new method and call this method from the original location.
This refactoring automatically detects all necessary inputs and outputs from the function and generates the argument list and return statement accordingly.
Expand All @@ -20,11 +55,7 @@
'''


class ExtractCommand(sublime_plugin.TextCommand):
# @TODO: create the commands ExtractDiffCommand and ExtractExecCommand

# name = 'extract diff'
# outputWindow = None
class ExtractCommand(sublime_plugin.TextCommand, Refactor):

def run(self, edit, execute=False):
window = sublime.active_window()
Expand All @@ -36,39 +67,13 @@ def run(self, edit, execute=False):
return ''

def runCommandLine(self, filePath, fromLine, toLine, newFcName, execute=False):
patch = ''
if (True == execute):
execute = '|patch -b ' + filePath
else:
execute = ''

# @TODO: this must be a top class constant (class Refactor, from where all commands inherit)
refactorFile = sublime.packages_path() + "/sublime-text-2-php-refactor/lib/refactor.phar"
command = "php " + refactorFile + " extract-method " + self.view.file_name() + " " + fromLine + "-" + toLine + " " + newFcName + execute
self.performAction('extract_' + newFcName, command)
patch = '|patch -b ' + filePath

# @TODO: create class Action(name, command)) with method execute(execute=False)
def performAction(self, name, command):
fileName = basename(self.view.file_name())

print 'Performing action: ' + name + ' (' + command + ')'
command = "php " + self.REFACTOR + " extract-method " + self.view.file_name() + " " + fromLine + "-" + toLine + " " + newFcName + patch
self.execute('extract_' + newFcName, command, execute)

p = subprocess.Popen(command, cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
if p.stdout is not None:
msg = p.stdout.readlines()
msg = '\n'.join(msg)
outputWindow = self.getOutputWindow(name + '_' + fileName + '.diff')
edit = outputWindow.begin_edit()
outputWindow.insert(edit, 0, msg)
outputWindow.end_edit(edit)
outputWindow.set_read_only(True)

def getOutputWindow(self, windowName, sintax='Diff'):
outputWindow = sublime.active_window().new_file()
outputWindow.set_name(windowName)
outputWindow.set_syntax_file('Packages/' + sintax + '/' + sintax + '.tmLanguage')
outputWindow.set_read_only(False)

return outputWindow

'''
def confirm(self):
Expand Down
Binary file modified sublime-text-2-php-refactor.pyc
Binary file not shown.

0 comments on commit 15c7c5e

Please sign in to comment.