From: Ɓukasz Rekucki Date: Fri, 4 Sep 2009 14:18:57 +0000 (+0200) Subject: Wielolinijkowy toolbar z dostosowywaniem wysokosci edytora. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/cd69a086aa9ce06b83f277b24e2992238654c320?ds=inline Wielolinijkowy toolbar z dostosowywaniem wysokosci edytora. Add w repo chyba dziala. --- 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() ); + } };