Wielolinijkowy toolbar z dostosowywaniem wysokosci edytora.
authorŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 14:18:57 +0000 (16:18 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Fri, 4 Sep 2009 14:18:57 +0000 (16:18 +0200)
Add w repo chyba dziala.

apps/explorer/views.py
lib/hg.py
project/static/css/toolbar.css
project/static/js/editor.js
project/templates/explorer/panels/xmleditor.html

index 251ad21..d2ba7f7 100644 (file)
@@ -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'],
index b94b0d6..6dd6e0c 100644 (file)
--- 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)
index aba534f..71940eb 100644 (file)
@@ -4,7 +4,7 @@
     background: #AAA;
     position: absolute;
     top: 0px; left:0px; right: 0px; 
-    height: 40pt;
+    height: auto;
     padding: 1pt;
     margin: 0pt;
 }
index 3ad2989..e615b79 100644 (file)
@@ -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');
             }
         });        
     });
index 76018ca..3a1baf1 100644 (file)
@@ -1,6 +1,6 @@
 {% load toolbar_tags %}
 
-<div class="iframe-container" style="position: absolute; top: 41pt; left:0px; right:0px; bottom: 0px;">
+<div class="iframe-container" style="position: absolute; top: 40px; left:0px; right:0px; bottom: 0px;">
        <textarea name="text">{{ text }}</textarea>
 </div>
 
@@ -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() );
+        }
 };
 
 </script>