Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge with master

  • Loading branch information...
commit 7d0db7d28bfbd35a6759a50f3bcb82c0fe6a8a1d 2 parents b8514c1 + 354cb74
Martin Alderete authored
25 ninja_ide/core/file_manager.py
View
@@ -172,18 +172,6 @@ def get_folder(fileName):
return os.path.dirname(fileName)
-def get_end_of_line(os_family):
- """
- Returns the chars to be used as end-of-line based
- """
- eol = {
- "Unix": None,
- "Windows": "\r\n",
- "Mac": "\r",
- }
- return eol.get(os_family)
-
-
def store_file_content(fileName, content, addExtension=True, newFile=False):
"""Save content on disk with the given file name."""
if fileName == '':
@@ -194,20 +182,19 @@ def store_file_content(fileName, content, addExtension=True, newFile=False):
if newFile and file_exists(fileName):
raise NinjaFileExistsException(fileName)
try:
+ flags = QtCore.QIODevice.WriteOnly | QtCore.QIODevice.Truncate
f = QtCore.QFile(fileName)
- if not f.open(QtCore.QIODevice.WriteOnly | QtCore.QIODevice.Truncate):
+ if settings.use_platform_specific_eol():
+ flags |= QtCore.QIODevice.Text
+
+ if not f.open(flags):
raise NinjaIOException(f.errorString())
stream = QtCore.QTextStream(f)
encoding = get_file_encoding(content)
- # NINJA-IDE internally always use UNIX style \n if the user set
- # a different EOL replace UNIX style with the user choice
- eol_chars = get_end_of_line(settings.END_OF_LINE)
- if eol_chars:
- content = content.replace('\n', eol_chars)
-
if encoding:
stream.setCodec(encoding)
+
encoded_stream = stream.codec().fromUnicode(content)
f.write(encoded_stream)
f.flush()
16 ninja_ide/core/settings.py
View
@@ -30,7 +30,6 @@
FONT_FAMILY = 'Monospace'
FONT_SIZE = 11
-EOL_DEFAULT = 'Unix'
if sys.platform == "darwin":
from PyQt4.QtGui import QKeySequence
from PyQt4.QtCore import Qt
@@ -38,11 +37,9 @@
FONT_FAMILY = 'Monaco'
FONT_SIZE = 11
OS_KEY = QKeySequence(Qt.CTRL).toString(QKeySequence.NativeText)
- EOL_DEFAULT = 'Mac'
elif sys.platform == "win32":
FONT_FAMILY = 'Courier'
FONT_SIZE = 10
- EOL_DEFAULT = 'Windows'
###############################################################################
# IDE
@@ -99,7 +96,7 @@
ALLOW_WORD_WRAP = False
INDENT = 4
# by default Unix (\n) is used
-END_OF_LINE = None
+USE_PLATFORM_END_OF_LINE = False
MARGIN_LINE = 80
SHOW_MARGIN_LINE = True
REMOVE_TRAILING_SPACES = True
@@ -264,10 +261,15 @@ def get_toolbar_item_for_plugins():
return TOOLBAR_ITEMS_PLUGINS
+def use_platform_specific_eol():
+ global USE_PLATFORM_END_OF_LINE
+ return USE_PLATFORM_END_OF_LINE
+
###############################################################################
# Utility functions to update (patch at runtime) pep8mod.py
###############################################################################
+
def pep8mod_refresh_checks():
"""
Force to reload all checks in pep8mod.py
@@ -324,8 +326,7 @@ def load_settings():
global SUPPORTED_EXTENSIONS
global WORKSPACE
global INDENT
- global END_OF_LINE
- global EOL_DEFAULT
+ global USE_PLATFORM_END_OF_LINE
global MARGIN_LINE
global REMOVE_TRAILING_SPACES
global SHOW_TABS_AND_SPACES
@@ -413,7 +414,8 @@ def load_settings():
SIZE_PROPORTION = float(qsettings.value(
'preferences/editor/minimapSizeProportion', 0.17))
INDENT = int(qsettings.value('preferences/editor/indent', 4))
- END_OF_LINE = qsettings.value('preferences/editor/endOfLine', EOL_DEFAULT)
+ eol = qsettings.value('preferences/editor/platformEndOfLine', 'false')
+ USE_PLATFORM_END_OF_LINE = eol == 'true'
MARGIN_LINE = int(qsettings.value('preferences/editor/marginLine', 80))
pep8mod_update_margin_line_length(MARGIN_LINE)
REMOVE_TRAILING_SPACES = qsettings.value(
15 ninja_ide/gui/dialogs/preferences.py
View
@@ -987,13 +987,9 @@ def __init__(self):
self._checkShowMargin.setChecked(settings.SHOW_MARGIN_LINE)
grid.addWidget(self._checkShowMargin, 2, 2, alignment=Qt.AlignTop)
#End of line
- grid.addWidget(QLabel(self.tr("End of Line:")), 3, 0, Qt.AlignRight)
- self._comboEndOfLine = QComboBox()
- self._comboEndOfLine.addItems(["Unix", "Windows", "Mac"])
- index = self._comboEndOfLine.findText(settings.END_OF_LINE)
- index = index if index > -1 else 0
- self._comboEndOfLine.setCurrentIndex(index)
- grid.addWidget(self._comboEndOfLine, 3, 1, alignment=Qt.AlignTop)
+ self._checkEndOfLine = QCheckBox(self.tr("Use Platform End of Line"))
+ self._checkEndOfLine.setChecked(settings.USE_PLATFORM_END_OF_LINE)
+ grid.addWidget(self._checkEndOfLine, 3, 1, alignment=Qt.AlignTop)
#Find Errors
self._checkHighlightLine = QCheckBox(
self.tr("Check: Highlight errors using Underline\n"
@@ -1083,8 +1079,9 @@ def save(self):
qsettings.beginGroup('editor')
qsettings.setValue('indent', self._spin.value())
settings.INDENT = self._spin.value()
- qsettings.setValue('endOfLine', self._comboEndOfLine.currentText())
- settings.END_OF_LINE = self._comboEndOfLine.currentText()
+ endOfLine = self._checkEndOfLine.isChecked()
+ qsettings.setValue('platformEndOfLine', endOfLine)
+ settings.USE_PLATFORM_END_OF_LINE = endOfLine
margin_line = self._spinMargin.value()
qsettings.setValue('marginLine', margin_line)
settings.MARGIN_LINE = margin_line
2  ninja_ide/gui/main_panel/main_container.py
View
@@ -623,8 +623,6 @@ def save_file(self, editorWidget=None):
editorWidget._file_saved()
return True
except Exception as reason:
- print(reason)
- raise
editorWidget.just_saved = False
logger.error('save_file: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
3  ninja_tests/core/examples/file_for_tests_write.py
View
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-
-print('testing')
38 ninja_tests/core/test_file_manager.py
View
@@ -14,6 +14,7 @@
#
# 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
from __future__ import unicode_literals
@@ -21,7 +22,6 @@
import os
from ninja_ide.core import file_manager
-from ninja_ide.core import settings
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -40,42 +40,6 @@ def test_read_file_content(self):
"print 'ñandú testing'\n").encode('utf-8')
self.assertEqual(content, expected)
- def __store_file_content(self, filename, content):
- return file_manager.store_file_content(filename, content)
-
- def test_change_eol_file_unix_content(self):
- # Write in Unix mode (Default)
- settings.END_OF_LINE = 'Unix'
- filename = os.path.join(self.examples_dir, 'file_for_tests_write.py')
- content = "# -*- coding: utf-8 -*-\n\nprint('testing')"
- self.__store_file_content(filename, content)
- with open(filename) as f:
- binary_content = f.read()
- expected = "# -*- coding: utf-8 -*-\n\nprint('testing')"
- self.assertEqual(binary_content, expected)
-
- def test_change_eol_file_windows_content(self):
- # Write in Windows mode
- settings.END_OF_LINE = 'Windows'
- filename = os.path.join(self.examples_dir, 'file_for_tests_write.py')
- content = "# -*- coding: utf-8 -*-\n\nprint('testing')"
- self.__store_file_content(filename, content)
- with open(filename) as f:
- binary_content = f.read()
- expected = "# -*- coding: utf-8 -*-\r\n\r\nprint('testing')"
- self.assertEqual(binary_content, expected)
-
- def test_change_eol_file_mac_content(self):
- # Write in Mac mode
- settings.END_OF_LINE = 'Mac'
- filename = os.path.join(self.examples_dir, 'file_for_tests_write.py')
- content = "# -*- coding: utf-8 -*-\n\nprint('testing')"
- self.__store_file_content(filename, content)
- with open(filename) as f:
- binary_content = f.read()
- expected = "# -*- coding: utf-8 -*-\r\rprint('testing')"
- self.assertEqual(binary_content, expected)
-
if __name__ == '__main__':
unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.