From cd69a086aa9ce06b83f277b24e2992238654c320 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Fri, 4 Sep 2009 16:18:57 +0200 Subject: [PATCH 1/1] Wielolinijkowy toolbar z dostosowywaniem wysokosci edytora. Add w repo chyba dziala. --- apps/explorer/views.py | 21 +++++++++++++++++-- lib/hg.py | 20 ++++++++++++++++-- project/static/css/toolbar.css | 2 +- project/static/js/editor.js | 2 ++ .../templates/explorer/panels/xmleditor.html | 12 ++++++++--- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/apps/explorer/views.py b/apps/explorer/views.py index 251ad214..d2ba7f79 100644 --- a/apps/explorer/views.py +++ b/apps/explorer/views.py @@ -153,7 +153,7 @@ def file_dc(request, path, repo): print "SAVING DC" # zapisz - repo._add_file(path, document.serialize()) + repo._write_file(path, document.serialize()) repo._commit( \ message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'), \ user=request.user.username ) @@ -184,7 +184,24 @@ def file_dc(request, path, repo): # Display the main editor view @login_required -def display_editor(request, path): +@with_repo +def display_editor(request, path, repo): + path = unicode(path).encode("utf-8") + if not repo.file_exists(path, models.user_branch(request.user)): + try: + data = repo.get_file(path, 'default') + print type(data) + + def new_file(): + repo._add_file(path, data) + repo._commit(message='File import from default branch', + user=request.user.username) + + repo.in_branch(new_file, models.user_branch(request.user) ) + except hg.RepositoryException, e: + return direct_to_templace(request, 'explorer/file_unavailble.html',\ + extra_context = { 'path': path, 'error': e }) + return direct_to_template(request, 'explorer/editor.html', extra_context={ 'hash': path, 'panel_list': ['lewy', 'prawy'], diff --git a/lib/hg.py b/lib/hg.py index b94b0d64..6dd6e0cb 100644 --- a/lib/hg.py +++ b/lib/hg.py @@ -44,13 +44,29 @@ class Repository(object): return self.in_branch(lambda: self._get_file(path), branch) def _get_file(self, path): + if not self._file_exists(path): + raise RepositoryException("File not availble in this branch.") + return self.repo.wread(path) - + + def file_exists(self, path, branch): + return self.in_branch(lambda: self._file_exists(path), branch) + + def _file_exists(self, path): + return self.repo.dirstate[path] != "?" + + def write_file(self, path, value, branch): + return self.in_branch(lambda: self._write_file(path, value), branch) + + def _write_file(self, path, value): + return self.repo.wwrite(path, value, []) + def add_file(self, path, value, branch): return self.in_branch(lambda: self._add_file(path, value), branch) def _add_file(self, path, value): - return self.repo.wwrite(path, value.encode('utf-8'), []) + self._write_file(path, value) + return self.repo.add( [path] ) def _commit(self, message, user=None): return self.repo.commit(text=message, user=user) diff --git a/project/static/css/toolbar.css b/project/static/css/toolbar.css index aba534fe..71940eb9 100644 --- a/project/static/css/toolbar.css +++ b/project/static/css/toolbar.css @@ -4,7 +4,7 @@ background: #AAA; position: absolute; top: 0px; left:0px; right: 0px; - height: 40pt; + height: auto; padding: 1pt; margin: 0pt; } diff --git a/project/static/js/editor.js b/project/static/js/editor.js index 3ad29898..e615b790 100644 --- a/project/static/js/editor.js +++ b/project/static/js/editor.js @@ -52,6 +52,7 @@ Panel.prototype.load = function (url) { panel_hooks = null; self.connectToolbar(); self.callHook('load'); + self.callHook('toolbarResized'); }, error: function(request, textStatus, errorThrown) { $.log('ajax', url, this.target, 'error:', textStatus, errorThrown); @@ -140,6 +141,7 @@ Panel.prototype.connectToolbar = function() else $(this).show(); }); + self.callHook('toolbarResized'); } }); }); diff --git a/project/templates/explorer/panels/xmleditor.html b/project/templates/explorer/panels/xmleditor.html index 76018ca7..3a1baf1c 100644 --- a/project/templates/explorer/panels/xmleditor.html +++ b/project/templates/explorer/panels/xmleditor.html @@ -1,6 +1,6 @@ {% load toolbar_tags %} -
+
@@ -14,7 +14,7 @@ panel_hooks = { var panel = self.contentDiv; var textareaId = 'xmleditor-' + Math.ceil(Math.random() * 1000000000); - $('textarea', panel).attr('id', textareaId); + $('textarea', panel).attr('id', textareaId); var texteditor = CodeMirror.fromTextArea(textareaId, { parserfile: 'parsexml.js', @@ -31,6 +31,7 @@ panel_hooks = { texteditor.grabKeys( $.fbind(self, self.hotkeyPressed), $.fbind(self, self.isHotkey) ); + } }) @@ -53,7 +54,12 @@ panel_hooks = { } }; $.extend(saveInfo, myInfo); - } + }, + + toolbarResized: function() { + $('.iframe-container', self.contentDiv).css('top', + $('.toolbar', self.contentDiv).outerHeight() ); + } }; -- 2.20.1