[kune-commits] r1075 - in trunk: . src/main/java/org/ourproject/kune/platf/client/ui/rte/basic

vjrj vjrj at ourproject.org
Fri Mar 13 22:36:50 CET 2009


Author: vjrj
Date: 2009-03-13 22:36:47 +0100 (Fri, 13 Mar 2009)
New Revision: 1075

Modified:
   trunk/TODO
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java
Log:
Complete - task Comments with user selection


Modified: trunk/TODO
===================================================================
--- trunk/TODO	2009-03-12 23:46:56 UTC (rev 1074)
+++ trunk/TODO	2009-03-13 21:36:47 UTC (rev 1075)
@@ -79,6 +79,16 @@
    http://www.w3.org/DesignIssues/Fragment.html
 ** vjrj <v> better RTE
 *** Pending
+**** W3C Range/Selection support in RTE
+     https://developer.mozilla.org/en/DOM/selection
+     http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html
+     As an intro:
+     http://www.quirksmode.org/dom/range_intro.html
+     http://maven.xwiki.org/site/xwiki-web/xwiki-web-wysiwyg/apidocs/com/xpn/xwiki/wysiwyg/client/dom/internal/AbstractRange.html
+     other links:
+     http://groups.google.com/group/rocket-gwt/browse_frm/thread/e56540d4168479c0/d25dca75958ba923?hl=en-GB&lnk=gst&q=Range#d25dca75958ba923
+     http://code.google.com/p/gwt-html-editor/source/browse/branches/gwt1.4/src/com/gc/gwt/wysiwyg/public/fckeditor/editor/_source/classes/fckdomrange_ie.js?r=81
+**** Quite urgent: Shortcuts propagation in Firefox
 **** with different menus (File/Blog ...)
 **** bidi support
 **** Insert special chars (for table or from unicode).
@@ -89,13 +99,6 @@
 **** Insert > Special char
 **** Insert > Page break (for printing)
 **** Shortcut to fonts (Ctrl + numbers)
-**** W3C Range support in RTE (selection)
-     As an intro:
-     http://www.quirksmode.org/dom/range_intro.html
-     http://maven.xwiki.org/site/xwiki-web/xwiki-web-wysiwyg/apidocs/com/xpn/xwiki/wysiwyg/client/dom/internal/AbstractRange.html
-     other links:
-     http://groups.google.com/group/rocket-gwt/browse_frm/thread/e56540d4168479c0/d25dca75958ba923?hl=en-GB&lnk=gst&q=Range#d25dca75958ba923
-     http://code.google.com/p/gwt-html-editor/source/browse/branches/gwt1.4/src/com/gc/gwt/wysiwyg/public/fckeditor/editor/_source/classes/fckdomrange_ie.js?r=81
 *** Links
    http://www.ongwt.com/post/2009/01/08/XWiki-:-Wysiwyg-editor-based-on-GWT
    http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/ie55/EditRegions/default.asp

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java	2009-03-12 23:46:56 UTC (rev 1074)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java	2009-03-13 21:36:47 UTC (rev 1075)
@@ -25,6 +25,9 @@
 import com.google.gwt.user.client.ui.KeyboardListener;
 import com.google.gwt.user.client.ui.Widget;
 import com.xpn.xwiki.wysiwyg.client.dom.Document;
+import com.xpn.xwiki.wysiwyg.client.dom.DocumentFragment;
+import com.xpn.xwiki.wysiwyg.client.dom.Range;
+import com.xpn.xwiki.wysiwyg.client.dom.Selection;
 
 public class RTEditorPanel implements RTEditorView {
 
@@ -115,14 +118,6 @@
         }
     }
 
-    public void addComment(String userName) {
-        String time = i18n.formatDateWithLocale(new Date(), true);
-        Element span = DOM.createSpan();
-        span.setInnerHTML("<em>" + i18n.t("type your comment here") + "</em> -" + userName + " " + time);
-        DOM.setElementProperty(span.<com.google.gwt.user.client.Element> cast(), "className", "k-rte-comment");
-        insertHtml("&nbsp;" + span.getString() + "&nbsp;");
-    }
-
     public void adjustSize(int height) {
         rta.setHeight("" + height);
     }
@@ -189,6 +184,25 @@
         return rta.getText();
     }
 
+    public void insertComment(String author) {
+        String comment = null;
+        createCommentAndSelectIt(author, comment);
+    }
+
+    public void insertCommentNotUsingSelection(String author) {
+        getFstRange().collapse(false);
+        createCommentAndSelectIt(author, null);
+        focus();
+    }
+
+    public void insertCommentUsingSelection(String author) {
+        DocumentFragment extracted = getFstRange().cloneContents();
+        extended.delete();
+        String comment = extracted.getInnerText();
+        createCommentAndSelectIt(author, comment);
+        focus();
+    }
+
     public void insertHorizontalRule() {
         extended.insertHorizontalRule();
     }
@@ -209,6 +223,10 @@
         extended.insertUnorderedList();
     }
 
+    public boolean isAnythingSelected() {
+        return !getDocument().getSelection().isCollapsed();
+    }
+
     public boolean isAttached() {
         return rta.isAttached();
     }
@@ -333,6 +351,34 @@
         presenter.fireOnEdit();
     }
 
+    private void createCommentAndSelectIt(String author, String comment) {
+        Element commentEl = createCommentElement(author, comment);
+        Range innerCommentRange = getDocument().createRange();
+        getFstRange().insertNode(commentEl);
+        innerCommentRange.selectNodeContents(commentEl.getFirstChild());
+        getSelection().addRange(innerCommentRange);
+        fireEdit();
+    }
+
+    private Element createCommentElement(String userName, String insertComment) {
+        String time = i18n.formatDateWithLocale(new Date(), true);
+        Element span = getDocument().createSpanElement();
+        String comment = insertComment != null ? insertComment : i18n.t("type your comment here");
+        span.setInnerHTML("<em>" + comment + "</em> -" + userName + " " + time);
+        DOM.setElementProperty(span.<com.google.gwt.user.client.Element> cast(), "className", "k-rte-comment");
+        // insertHtml("&nbsp;" + span.getString() + "&nbsp;");
+        return span;
+    }
+
+    private Range getFstRange() {
+        return getSelection().getRangeAt(0);
+    }
+
+    private Selection getSelection() {
+        Selection selection = getDocument().getSelection();
+        return selection;
+    }
+
     /**
      * Updates the status of all the stateful buttons.
      */

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java	2009-03-12 23:46:56 UTC (rev 1074)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java	2009-03-13 21:36:47 UTC (rev 1075)
@@ -420,11 +420,33 @@
         ActionToolbarMenuDescriptor<Object> comment = new ActionToolbarMenuDescriptor<Object>(accessRol, topbar,
                 new Listener0() {
                     public void onEvent() {
-                        view.focus();
-                        String author = session.isLogged() ? session.getCurrentUser().getShortName()
-                                : i18n.t("anonymous user");
-                        view.addComment(author);
-                        fireOnEdit();
+                        deferred.addCommand(new Listener0() {
+                            public void onEvent() {
+                                view.focus();
+                                final String author = session.isLogged() ? session.getCurrentUser().getShortName()
+                                        : i18n.t("anonymous user");
+                                if (view.isAnythingSelected()) {
+                                    NotifyUser.askConfirmation(i18n.t("Insert a comment"),
+                                            i18n.t("Include the selected text in the comment?"), new Listener0() {
+                                                public void onEvent() {
+                                                    // include selection in
+                                                    // comment
+                                                    view.insertCommentUsingSelection(author);
+                                                }
+                                            }, new Listener0() {
+                                                public void onEvent() {
+                                                    // not include selection in
+                                                    // comment;
+                                                    view.insertCommentNotUsingSelection(author);
+                                                }
+                                            });
+                                } else {
+                                    // Nothing selected > create comment in
+                                    // insertion point
+                                    view.insertComment(author);
+                                }
+                            }
+                        });
                     }
                 });
         comment.setEnableCondition(new ActionEnableCondition<Object>() {
@@ -637,11 +659,16 @@
         final ActionToolbarMenuDescriptor<Object> devInfo = new ActionToolbarMenuDescriptor<Object>(accessRol, topbar,
                 new Listener0() {
                     public void onEvent() {
-                        Selection selection = view.getDocument().getSelection();
-                        String info = "range count: " + selection.getRangeCount() + "<br/>focus offset: "
-                                + selection.getFocusOffset() + "<br/>anchor offset:" + selection.getAnchorOffset()
-                                + "<br/>range 0 as html: " + selection.getRangeAt(0).toHTML();
-                        NotifyUser.info(info);
+                        deferred.addCommand(new Listener0() {
+                            public void onEvent() {
+                                Selection selection = view.getDocument().getSelection();
+                                String info = "range count: " + selection.getRangeCount() + "<br/>focus offset: "
+                                        + selection.getFocusOffset() + "<br/>anchor offset:"
+                                        + selection.getAnchorOffset() + "<br/>range 0 as html: "
+                                        + selection.getRangeAt(0).toHTML();
+                                NotifyUser.info(info);
+                            }
+                        });
                     }
                 });
         devInfo.setTextDescription(i18n.t("Developers info"));
@@ -682,7 +709,7 @@
         actions.add(withNoItem(comment));
         actions.add(withNoItem(undoBtn));
         actions.add(withNoItem(redoBtn));
-        actions.add(withNoItem(devInfo));
+        // actions.add(withNoItem(devInfo));
 
         for (String fontName : this.fontNames) {
             ActionToolbarMenuDescriptor<Object> fontNameAction = createFontNameAction(canBeBasic, fontName);

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java	2009-03-12 23:46:56 UTC (rev 1074)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java	2009-03-13 21:36:47 UTC (rev 1075)
@@ -10,8 +10,6 @@
 
     void addActions(ActionItemCollection<Object> actions);
 
-    void addComment(String userName);
-
     void adjustSize(int height);
 
     boolean canBeBasic();
@@ -34,6 +32,12 @@
 
     String getText();
 
+    void insertComment(String author);
+
+    void insertCommentNotUsingSelection(String author);
+
+    void insertCommentUsingSelection(String author);
+
     void insertHorizontalRule();
 
     void insertHtml(String html);
@@ -44,6 +48,8 @@
 
     void insertUnorderedList();
 
+    boolean isAnythingSelected();
+
     boolean isAttached();
 
     boolean isBold();




More information about the kune-commits mailing list