Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents 6349bad + 9829701 commit 36599aed05893e3ad831b31f011a59a323fedede @malderete malderete committed Oct 6, 2012
View
@@ -1,5 +1,6 @@
{
"mainFile": "ninja-ide.py",
+ "use-tabs": false,
"venv": "",
"relatedProjects": [],
"name": "NINJA-IDE",
@@ -8,6 +9,7 @@
"pythonPath": "python",
"preExecScript": "",
"programParams": "",
+ "indentation": 4,
"PYTHONPATH": "",
"supported-extensions": [
".py",
@@ -37,6 +37,8 @@
from PyQt4.QtGui import QIcon
from PyQt4.QtGui import QFileDialog
from PyQt4.QtGui import QMessageBox
+from PyQt4.QtGui import QSpinBox
+from PyQt4.QtGui import QCheckBox
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import Qt
@@ -103,6 +105,8 @@ def save_properties(self):
self._item.venv = self.projectExecution.txtVenvPath.text()
extensions = self.projectData.txtExtensions.text().split(', ')
self._item.extensions = tuple(extensions)
+ self._item.indentation = self.projectData.spinIndentation.value()
+ self._item.useTabs = self.projectData.checkUseTabs.isChecked()
related = self.projectMetadata.txt_projects.toPlainText()
related = [path for path in related.split('\n') if path != '']
self._item.related_projects = related
@@ -115,6 +119,8 @@ def save_properties(self):
project['mainFile'] = self._item.mainFile
project['project-type'] = self._item.projectType
project['supported-extensions'] = self._item.extensions
+ project['indentation'] = self._item.indentation
+ project['use-tabs'] = self._item.useTabs
project['pythonPath'] = self._item.pythonPath # FIXME
project['PYTHONPATH'] = self._item.PYTHONPATH
project['preExecScript'] = self._item.preExecScript
@@ -187,6 +193,14 @@ def __init__(self, parent):
grid.addWidget(QLabel(self.tr("Supported Extensions:")), 5, 0)
grid.addWidget(self.txtExtensions, 5, 1)
+ grid.addWidget(QLabel(self.tr("Indentation: ")), 6, 0)
+ self.spinIndentation = QSpinBox()
+ self.spinIndentation.setValue(self._parent._item.indentation)
+ self.spinIndentation.setMinimum(1)
+ grid.addWidget(self.spinIndentation, 6, 1)
+ self.checkUseTabs = QCheckBox(self.tr("Use Tabs."))
+ self.checkUseTabs.setChecked(self._parent._item.useTabs)
+ grid.addWidget(self.checkUseTabs, 6, 2)
class ProjectExecution(QWidget):
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with NINJA-IDE; If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
-
import re
from tokenize import generate_tokens, TokenError
@@ -43,6 +42,7 @@
from ninja_ide import resources
from ninja_ide.core import settings
from ninja_ide.core import file_manager
+from ninja_ide.tools import json_manager
from ninja_ide.tools.completion import completer_widget
from ninja_ide.gui.main_panel import itab_item
from ninja_ide.gui.editor import highlighter
@@ -77,7 +77,7 @@ class Editor(QPlainTextEdit, itab_item.ITabItem):
"""
###############################################################################
- def __init__(self, filename, project):
+ def __init__(self, filename, project, project_obj=None):
QPlainTextEdit.__init__(self)
itab_item.ITabItem.__init__(self)
#Config Editor
@@ -109,6 +109,13 @@ def __init__(self, filename, project):
self.__encoding = None
#Completer
self.completer = completer_widget.CodeCompletionWidget(self)
+ #Indentation
+ if project_obj is not None:
+ self.indent = project_obj.indentation
+ self.useTabs = project_obj.useTabs
+ else:
+ self.indent = settings.INDENT
+ self.useTabs = settings.USE_TABS
#Flag to dont bug the user when answer *the modification dialog*
self.ask_if_externally_modified = False
self.just_saved = False
@@ -152,7 +159,7 @@ def __init__(self, filename, project):
self.connect(self, SIGNAL("updateRequest(const QRect&, int)"),
self._mini.update_visible_area)
#Set tab usage
- if settings.USE_TABS:
+ if self.useTabs:
self.set_tab_usage()
#Context Menu Options
@@ -188,7 +195,7 @@ def set_flags(self):
self.setCenterOnScroll(settings.CENTER_ON_SCROLL)
def set_tab_usage(self):
- tab_size = self.pos_margin / settings.MARGIN_LINE * settings.INDENT
+ tab_size = self.pos_margin / settings.MARGIN_LINE * self.indent
self.setTabStopWidth(tab_size)
if self._mini:
self._mini.setTabStopWidth(tab_size)
@@ -502,10 +509,10 @@ def indent_more(self):
cursor.setPosition(block.position())
while block != end:
cursor.setPosition(block.position())
- if settings.USE_TABS:
+ if self.useTabs:
cursor.insertText('\t')
else:
- cursor.insertText(' ' * settings.INDENT)
+ cursor.insertText(' ' * self.indent)
block = block.next()
#End a undo block
@@ -529,15 +536,15 @@ def indent_less(self):
while block != end:
cursor.setPosition(block.position())
#Select Settings.indent chars from the current line
- if settings.USE_TABS:
+ if self.useTabs:
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
else:
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor,
- settings.INDENT)
+ self.indent)
text = cursor.selectedText()
- if not settings.USE_TABS and text == ' ' * settings.INDENT:
+ if not self.useTabs and text == ' ' * self.indent:
cursor.removeSelectedText()
- elif settings.USE_TABS and text == '\t':
+ elif self.useTabs and text == '\t':
cursor.removeSelectedText()
block = block.next()
@@ -624,22 +631,22 @@ def resizeEvent(self, event):
def __insert_indentation(self, event):
if self.textCursor().hasSelection():
self.indent_more()
- elif settings.USE_TABS:
+ elif self.useTabs:
return False
else:
- self.textCursor().insertText(' ' * settings.INDENT)
+ self.textCursor().insertText(' ' * self.indent)
return True
def __backspace(self, event):
- if self.textCursor().hasSelection() or settings.USE_TABS:
+ if self.textCursor().hasSelection() or self.useTabs:
return False
cursor = self.textCursor()
cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
text = cursor.selection().toPlainText()
- if (len(text) % settings.INDENT == 0) and text.isspace():
+ if (len(text) % self.indent == 0) and text.isspace():
cursor.movePosition(QTextCursor.StartOfLine)
cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor,
- settings.INDENT)
+ self.indent)
cursor.removeSelectedText()
return True
@@ -654,6 +661,14 @@ def __home_pressed(self, event):
self.moveCursor(QTextCursor.WordRight, move)
return True
+ cursor = self.textCursor()
+ position = cursor.position()
+ self.moveCursor(QTextCursor.StartOfLine, move)
+ self.moveCursor(QTextCursor.WordRight, move)
+ if position != self.textCursor().position() and \
+ cursor.block().text().startswith(' '):
+ return True
+
def __ignore_extended_line(self, event):
if event.modifiers() == Qt.ShiftModifier:
return True
@@ -726,7 +741,7 @@ def __brace_completion(self, event):
def __auto_indent(self, event):
text = unicode(self.textCursor().block().previous().text())
- spaces = helpers.get_indentation(text)
+ spaces = helpers.get_indentation(text, self.indent, self.useTabs)
self.textCursor().insertText(spaces)
if text != '' and text == ' ' * len(text):
self.moveCursor(QTextCursor.Up)
@@ -1129,8 +1144,8 @@ def async_highlight(self):
def create_editor(fileName='', project=None, syntax=None,
- use_open_highlight=False):
- editor = Editor(fileName, project)
+ use_open_highlight=False, project_obj=None):
+ editor = Editor(fileName, project, project_obj=project_obj)
#if syntax is specified, use it
if syntax:
editor.register_syntax(syntax)
@@ -45,24 +45,24 @@ def get_leading_spaces(line):
return ''
-def get_indentation(line):
+def get_indentation(line, indent=settings.INDENT, useTabs=settings.USE_TABS):
global patIndent
global endCharsForIndent
indentation = ''
if len(line) > 0 and line[-1] in endCharsForIndent:
- if settings.USE_TABS:
+ if useTabs:
indentation = '\t'
else:
- indentation = ' ' * settings.INDENT
+ indentation = ' ' * indent
elif len(line) > 0 and line[-1] == ',':
count = filter(lambda x:
(line.count(x) - line.count(closeBraces[x])) % 2 != 0,
endCharsForIndent[1:])
if count:
- if settings.USE_TABS:
+ if useTabs:
indentation = '\t'
else:
- indentation = ' ' * settings.INDENT
+ indentation = ' ' * indent
space = patIndent.match(line)
if space is not None:
return space.group() + indentation
@@ -136,7 +136,7 @@ def insert_coding_line(editorWidget):
def replace_tabs_with_spaces(editorWidget):
text = editorWidget.toPlainText()
- text = text.replace('\t', ' ' * settings.INDENT)
+ text = text.replace('\t', ' ' * editorWidget.indent)
editorWidget.setPlainText(text)
@@ -518,12 +518,12 @@ def check_for_assistance_completion(editorWidget, line):
if init.startswith('__init__')]:
return
editorWidget.textCursor().insertText('\n')
- indent = get_indentation(line)
+ indent = get_indentation(line, editorWidget.indent, editorWidget.useTabs)
editorWidget.textCursor().insertText(indent + 'def __init__(self):\n')
- if settings.USE_TABS:
+ if editorWidget.useTabs:
indent += '\t'
else:
- indent += ' ' * settings.INDENT
+ indent += ' ' * editorWidget.indent
if line.find('(') != -1:
classes = line.split('(')
parents = []
@@ -316,6 +316,13 @@ def get_project_main_file(self):
return self._treeProjects.get_project_main_file()
return ''
+ def get_project_given_filename(self, filename):
+ projects = self.get_opened_projects()
+ for project in projects:
+ if filename.startswith(project.path):
+ return project
+ return None
+
def get_opened_projects(self):
if self._treeProjects:
return self._treeProjects.get_open_projects()
@@ -787,6 +787,8 @@ def __init__(self, parent, _name, path):
self.mainFile = project.get('mainFile', '')
self.preExecScript = project.get('preExecScript', '')
self.postExecScript = project.get('postExecScript', '')
+ self.indentation = project.get('indentation', settings.INDENT)
+ self.useTabs = project.get('use-tabs', settings.USE_TABS)
self.extensions = project.get('supported-extensions',
settings.SUPPORTED_EXTENSIONS)
self.pythonPath = project.get('pythonPath', settings.PYTHON_PATH)
@@ -259,8 +259,11 @@ def move_tab_to_next_split(self, tab_from):
def add_editor(self, fileName="", project=None, tabIndex=None,
syntax=None, use_open_highlight=False):
+
+ project_obj = self._parent.explorer.get_project_given_filename(fileName)
editorWidget = editor.create_editor(fileName=fileName, project=project,
- syntax=syntax, use_open_highlight=use_open_highlight)
+ syntax=syntax, use_open_highlight=use_open_highlight,
+ project_obj=project_obj)
if not fileName:
tabName = "New Document"
@@ -59,14 +59,14 @@ def __init__(self):
def unload_module(self):
self.cdaemon.unload_module(self.module_id)
- def analyze_file(self, path, source=None):
+ def analyze_file(self, path, source=None, indent=settings.INDENT, useTabs=settings.USE_TABS):
if source is None:
with open(path) as f:
source = f.read()
split_last_lines = source.rsplit('\n', 2)
if len(split_last_lines) > 1 and \
split_last_lines[-2].endswith(':') and split_last_lines[-1] == '':
- indent = helpers.get_indentation(split_last_lines[-2])
+ indent = helpers.get_indentation(split_last_lines[-2], indent, useTabs)
source += '%spass;' % indent
self.module_id = path
@@ -106,7 +106,7 @@ def update_metadata(self, cursor):
cursor.block().blockNumber() != self._block:
source = self._editor.get_text()
source = source.encode(self._editor.encoding)
- self.cc.analyze_file(self._editor.ID, source)
+ self.cc.analyze_file(self._editor.ID, source, self._editor.indent, self._editor.useTabs)
self._revision = self._editor.document().revision()
self._block = cursor.block().blockNumber()

0 comments on commit 36599ae

Please sign in to comment.