[kune-commits] r1076 - in trunk: . src/main/java/com/xpn/xwiki/wysiwyg src/main/java/org/ourproject/kune/platf/client/actions src/main/java/org/ourproject/kune/platf/client/ui/rte src/main/java/org/ourproject/kune/platf/client/ui/rte/basic src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink src/main/java/org/ourproject/kune/platf/client/ui/rte/saving src/main/java/org/ourproject/kune/workspace/client src/main/java/org/ourproject/kune/workspace/client/editor src/main/java/org/ourproject/kune/workspace/client/events src/main/java/org/ourproject/kune/workspace/client/hello src/test/java/org/ourproject/kune/platf/client/actions src/test/java/org/ourproject/kune/platf/client/ui/rte

vjrj vjrj at ourproject.org
Sun Mar 15 18:29:43 CET 2009


Author: vjrj
Date: 2009-03-15 18:29:41 +0100 (Sun, 15 Mar 2009)
New Revision: 1076

Added:
   trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcutRegister.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfo.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfoTest.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/events/
   trunk/src/main/java/org/ourproject/kune/workspace/client/events/GlobalShortcutRegister.java
   trunk/src/test/java/org/ourproject/kune/platf/client/ui/rte/insertlink/
Modified:
   trunk/TODO
   trunk/src/main/java/com/xpn/xwiki/wysiwyg/Wysiwyg.gwt.xml
   trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionDescriptor.java
   trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcut.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java
   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
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java
   trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java
   trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java
   trunk/src/test/java/org/ourproject/kune/platf/client/actions/ActionShortcutTest.java
Log:
Complete - task Global shortcuts and solved not propagation of shortcuts to browser


Modified: trunk/TODO
===================================================================
--- trunk/TODO	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/TODO	2009-03-15 17:29:41 UTC (rev 1076)
@@ -88,7 +88,17 @@
      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
+**** Insert/Edit link
+***** use cases
+     ^<a href="http://example.com">sample</a>^   --- Parse and edit
+     <a href="http://example.com">s^ample</a>    --- Parse and edit
+     <a href="http://example.com">s^amp^le</a>   --- Parse and edit
+     ^some text <a href="http://example.com">samp^le</a>   --- new link with get inner content?
+**** Quite urgent: Shortcuts propagation to browser
+     http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/Event.html#preventDefault
+     http://openkm.cvs.sourceforge.net/viewvc/openkm/openkm/src/es/git/openkm/frontend/client/panel/ExtendedDockPanel.java?revision=1.20&view=markup
+     http://openkm.cvs.sourceforge.net/viewvc/openkm/openkm/src/es/git/openkm/frontend/client/util/Keyboard.java?revision=1.20&view=markup
+     http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/
 **** with different menus (File/Blog ...)
 **** bidi support
 **** Insert special chars (for table or from unicode).

Modified: trunk/src/main/java/com/xpn/xwiki/wysiwyg/Wysiwyg.gwt.xml
===================================================================
--- trunk/src/main/java/com/xpn/xwiki/wysiwyg/Wysiwyg.gwt.xml	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/com/xpn/xwiki/wysiwyg/Wysiwyg.gwt.xml	2009-03-15 17:29:41 UTC (rev 1076)
@@ -4,7 +4,9 @@
   <inherits name="com.google.gwt.http.HTTP"/>
   <inherits name="com.google.gwt.junit.JUnit"/>
 
+<!--
   <stylesheet src="Wysiwyg.css"/>
+ -->
 
   <define-property name="old.user.agent" values="yes,no"/>
 

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionDescriptor.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionDescriptor.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionDescriptor.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -28,7 +28,7 @@
 /**
  * The Class ActionDescriptor.
  */
-public abstract class ActionDescriptor<T> {
+public class ActionDescriptor<T> {
 
     public static final int NO_POSITION = -1;
 

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcut.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcut.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcut.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -18,11 +18,11 @@
     private final char key;
     private final String keyName;
 
-    public ActionShortcut(boolean alt, boolean ctrl, boolean shift, char key) {
-        this(alt, ctrl, shift, key, NO_KEYNAME);
+    public ActionShortcut(boolean ctrl, boolean alt, boolean shift, char key) {
+        this(ctrl, alt, shift, key, NO_KEYNAME);
     }
 
-    public ActionShortcut(boolean alt, boolean ctrl, boolean shift, char key, String keyName) {
+    public ActionShortcut(boolean ctrl, boolean alt, boolean shift, char key, String keyName) {
         this.alt = alt;
         this.ctrl = ctrl;
         this.shift = shift;
@@ -31,28 +31,28 @@
     }
 
     public ActionShortcut(boolean ctrl, boolean shift, char key) {
-        this(false, ctrl, shift, key, NO_KEYNAME);
+        this(ctrl, false, shift, key, NO_KEYNAME);
     }
 
     public ActionShortcut(boolean ctrl, boolean shift, char key, String keyName) {
-        this(false, ctrl, shift, key, keyName);
+        this(ctrl, false, shift, key, keyName);
     }
 
     public ActionShortcut(boolean ctrl, char key) {
-        this(false, ctrl, false, key, NO_KEYNAME);
+        this(ctrl, false, false, key, NO_KEYNAME);
     }
 
     public ActionShortcut(boolean ctrl, char key, String keyName) {
-        this(false, ctrl, false, key, keyName);
+        this(ctrl, false, false, key, keyName);
     }
 
     public ActionShortcut(char key, int modifiers) {
-        this(has(modifiers, KeyboardListener.MODIFIER_ALT), has(modifiers, KeyboardListener.MODIFIER_CTRL), has(
+        this(has(modifiers, KeyboardListener.MODIFIER_CTRL), has(modifiers, KeyboardListener.MODIFIER_ALT), has(
                 modifiers, KeyboardListener.MODIFIER_SHIFT), key, NO_KEYNAME);
     }
 
     public ActionShortcut(char key, int modifiers, String keyName) {
-        this(has(modifiers, KeyboardListener.MODIFIER_ALT), has(modifiers, KeyboardListener.MODIFIER_CTRL), has(
+        this(has(modifiers, KeyboardListener.MODIFIER_CTRL), has(modifiers, KeyboardListener.MODIFIER_ALT), has(
                 modifiers, KeyboardListener.MODIFIER_SHIFT), key, keyName);
     }
 

Added: trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcutRegister.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcutRegister.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/actions/ActionShortcutRegister.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -0,0 +1,60 @@
+package org.ourproject.kune.platf.client.actions;
+
+import java.util.HashMap;
+
+import org.ourproject.kune.platf.client.dto.AccessRolDTO;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.calclab.suco.client.events.Listener0;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.KeyboardListenerCollection;
+
+public class ActionShortcutRegister {
+
+    @SuppressWarnings("unchecked")
+    private final HashMap<ActionShortcut, ActionItem> shortcuts;
+
+    @SuppressWarnings("unchecked")
+    public ActionShortcutRegister() {
+        shortcuts = new HashMap<ActionShortcut, ActionItem>();
+    }
+
+    @SuppressWarnings("unchecked")
+    public ActionItem get(ActionShortcut shortcut) {
+        return shortcuts.get(shortcut);
+    }
+
+    @SuppressWarnings("unchecked")
+    public ActionItem get(Event event) {
+        int modifiers = KeyboardListenerCollection.getKeyboardModifiers(event);
+        if (event.getTypeInt() == Event.ONKEYDOWN && modifiers != 0) {
+            ActionShortcut shortcut = new ActionShortcut((char) event.getKeyCode(), modifiers);
+            Log.debug("Shortcut pressed" + shortcut.toString());
+            return shortcuts.get(shortcut);
+        }
+        // if (modifiers != 0) {
+        // Log.debug("Not action associated with this shortcut");
+        // }
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public void put(ActionShortcut shortcut, ActionItem actionItem) {
+        if (shortcuts.get(shortcut) != null) {
+            Log.warn("Shortcut" + shortcut + " already registered");
+        }
+        shortcuts.put(shortcut, actionItem);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void put(ActionShortcut shortcut, final Listener0 listener) {
+        ActionDescriptor descriptor = new ActionDescriptor(AccessRolDTO.Viewer, new Listener0() {
+            public void onEvent() {
+                listener.onEvent();
+            }
+        });
+        ActionItem item = new ActionItem(descriptor, null);
+        put(shortcut, item);
+    }
+
+}

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/TestRTEDialog.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -25,7 +25,7 @@
         vp.add((Widget) ((ActionToolbarPanel<Object>) basicEditor.getTopBar().getView()).getToolbar());
         vp.add((Widget) ((ActionToolbarPanel<Object>) basicEditor.getSndBar().getView()).getToolbar());
         final RTEditorPanel editorPanel = (RTEditorPanel) basicEditor.getEditorArea();
-        vp.add(editorPanel.getRTE());
+        vp.add(editorPanel);
         basicEditor.setExtended(true);
         vp.setWidth("100%");
         dialog.add(vp);
@@ -34,7 +34,7 @@
             public void onResize(Window source, int width, int height) {
                 int newHeight = height - 26 * 2 - 40;
                 editorPanel.adjustSize(newHeight);
-                vp.setCellHeight(editorPanel.getRTE(), "" + newHeight);
+                vp.setCellHeight(editorPanel, "" + newHeight);
             }
         });
     }

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditor.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -26,6 +26,8 @@
 
     ActionAddCondition<Object> canBeExtended();
 
+    void detach();
+
     View getEditorArea();
 
     String getHtml();
@@ -36,8 +38,6 @@
 
     ActionToolbar<Object> getTopBar();
 
-    void reset();
-
     void setExtended(boolean extended);
 
     void setHtml(String html);

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-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPanel.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -1,111 +1,68 @@
 package org.ourproject.kune.platf.client.ui.rte.basic;
 
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_DOWN;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_END;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_ESCAPE;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_HOME;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_LEFT;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_PAGEDOWN;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_PAGEUP;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_RIGHT;
+import static com.google.gwt.user.client.ui.KeyboardListener.KEY_UP;
+
 import java.util.Date;
-import java.util.HashMap;
 
 import org.ourproject.kune.platf.client.actions.ActionDescriptor;
 import org.ourproject.kune.platf.client.actions.ActionItem;
 import org.ourproject.kune.platf.client.actions.ActionItemCollection;
 import org.ourproject.kune.platf.client.actions.ActionManager;
 import org.ourproject.kune.platf.client.actions.ActionShortcut;
+import org.ourproject.kune.platf.client.actions.ActionShortcutRegister;
 import org.ourproject.kune.platf.client.i18n.I18nUITranslationService;
 import org.ourproject.kune.platf.client.ui.rte.RichTextArea;
-import org.ourproject.kune.platf.client.ui.rte.RichTextArea.BasicFormatter;
-import org.ourproject.kune.platf.client.ui.rte.RichTextArea.ExtendedFormatter;
-import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize;
-import org.ourproject.kune.platf.client.ui.rte.RichTextArea.Justification;
 
-import com.allen_sauer.gwt.log.client.Log;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.IFrameElement;
 import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.ui.ChangeListener;
-import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.FocusListener;
-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 {
+public class RTEditorPanel extends RichTextArea implements RTEditorView {
 
-    private class EventListener implements ClickListener, ChangeListener, KeyboardListener, FocusListener {
+    private class EventListener implements FocusListener {
 
-        public void onChange(Widget sender) {
-            presenter.fireOnEdit();
-        }
-
-        public void onClick(Widget sender) {
-            if (sender == rta) {
-                // We use the RichTextArea's onKeyUp event to update the
-                // toolbar status. This will catch any cases where the user
-                // moves the cursor using the keyboard, or uses one of the
-                // browser's built-in keyboard shortcuts.
-                updateStatus();
-            }
-        }
-
         public void onFocus(Widget sender) {
             presenter.onEditorFocus();
         }
 
-        public void onKeyDown(final Widget sender, final char keyCode, final int modifiers) {
-        }
-
-        public void onKeyPress(final Widget sender, final char keyCode, final int modifiers) {
-        }
-
-        public void onKeyUp(final Widget sender, final char keyCode, final int modifiers) {
-            if (sender == rta) {
-                // We use the RichTextArea's onKeyUp event to update the
-                // toolbar status.
-                // This will catch any cases where the user moves the cursor
-                // using the keyboard, or uses one of the browser's built-in
-                // keyboard shortcuts.
-
-                updateStatus();
-                fireEdit();
-                if (modifiers != 0) {
-                    Log.debug("RTE shortcut pressed (" + modifiers + ", " + keyCode + ")");
-                    ActionItem<Object> actionItem = shortcuts.get(new ActionShortcut(keyCode, modifiers));
-                    if (actionItem != null) {
-                        actionManager.doAction(actionItem);
-                        updateStatus();
-                    } else {
-                        Log.debug("...but not mapped to any action");
-                    }
-                }
-            }
-        }
-
         public void onLostFocus(Widget sender) {
-
         }
     }
     private final I18nUITranslationService i18n;
-    private final RichTextArea rta;
     private final BasicFormatter basic;
     private final ExtendedFormatter extended;
-    private final HashMap<ActionShortcut, ActionItem<Object>> shortcuts;
-    private final ActionManager actionManager;
     private final RTEditorPresenter presenter;
+    private final ActionManager actionManager;
+    private final ActionShortcutRegister shortcutRegister;
 
-    public RTEditorPanel(final RTEditorPresenter presenter, I18nUITranslationService i18n, ActionManager actionManager) {
+    public RTEditorPanel(final RTEditorPresenter presenter, I18nUITranslationService i18n,
+            final ActionManager actionManager) {
         this.presenter = presenter;
         this.i18n = i18n;
         this.actionManager = actionManager;
-        rta = new RichTextArea();
-        basic = rta.getBasicFormatter();
-        extended = rta.getExtendedFormatter();
-        shortcuts = new HashMap<ActionShortcut, ActionItem<Object>>();
+        basic = getBasicFormatter();
+        extended = getExtendedFormatter();
+        shortcutRegister = new ActionShortcutRegister();
         EventListener listener = new EventListener();
-        rta.addClickListener(listener);
-        rta.addKeyboardListener(listener);
-        rta.addFocusListener(listener);
-        rta.setWidth("96%");
-        rta.setHeight("100%");
+        addFocusListener(listener);
+        setWidth("97%");
+        setHeight("100%");
+
     }
 
     public void addActions(ActionItemCollection<Object> actionItems) {
@@ -113,13 +70,13 @@
             ActionDescriptor<Object> action = actionItem.getAction();
             if (action.hasShortcut() && action.mustBeAdded(null)) {
                 ActionShortcut shortcut = action.getShortcut();
-                shortcuts.put(shortcut, actionItem);
+                shortcutRegister.put(shortcut, actionItem);
             }
         }
     }
 
     public void adjustSize(int height) {
-        rta.setHeight("" + height);
+        setHeight("" + height);
     }
 
     public boolean canBeBasic() {
@@ -147,7 +104,7 @@
     }
 
     public void focus() {
-        rta.setFocus(true);
+        setFocus(true);
     }
 
     /**
@@ -165,25 +122,13 @@
      *         copied from xwiki
      */
     public Document getDocument() {
-        if (rta.getElement().getTagName().equalsIgnoreCase("iframe")) {
-            return IFrameElement.as(rta.getElement()).getContentDocument().cast();
+        if (getElement().getTagName().equalsIgnoreCase("iframe")) {
+            return IFrameElement.as(getElement()).getContentDocument().cast();
         } else {
             return null;
         }
     }
 
-    public String getHtml() {
-        return rta.getHTML();
-    }
-
-    public Widget getRTE() {
-        return rta;
-    }
-
-    public String getText() {
-        return rta.getText();
-    }
-
     public void insertComment(String author) {
         String comment = null;
         createCommentAndSelectIt(author, comment);
@@ -227,10 +172,6 @@
         return !getDocument().getSelection().isCollapsed();
     }
 
-    public boolean isAttached() {
-        return rta.isAttached();
-    }
-
     public boolean isBold() {
         return basic.isBold();
     }
@@ -271,6 +212,38 @@
         extended.leftIndent();
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public void onBrowserEvent(Event event) {
+        switch (DOM.eventGetType(event)) {
+        case Event.ONCLICK:
+            updateStatus();
+            super.onBrowserEvent(event);
+            break;
+        case Event.ONKEYDOWN:
+            ActionItem actionItem = shortcutRegister.get(event);
+            if (actionItem != null) {
+                updateStatus();
+                fireEdit();
+                event.cancelBubble(true);
+                event.preventDefault();
+                actionManager.doAction(actionItem);
+                updateStatus();
+            } else {
+                super.onBrowserEvent(event);
+                updateStatus();
+                if (isAnEditionKey(event.getKeyCode())) {
+                    fireEdit();
+                }
+            }
+            break;
+        default:
+            // Rest of events
+            super.onBrowserEvent(event);
+            updateStatus();
+        }
+    }
+
     public void paste() {
         extended.paste();
     }
@@ -307,14 +280,6 @@
         basic.setForeColor(color);
     }
 
-    public void setHtml(String html) {
-        rta.setHTML(html);
-    }
-
-    public void setText(String text) {
-        rta.setText(text);
-    }
-
     public void toggleBold() {
         basic.toggleBold();
     }
@@ -375,10 +340,19 @@
     }
 
     private Selection getSelection() {
-        Selection selection = getDocument().getSelection();
-        return selection;
+        return getDocument().getSelection();
     }
 
+    private boolean isAnEditionKey(int keyCode) {
+        if (keyCode != KEY_HOME && keyCode != KEY_END && keyCode != KEY_UP && keyCode != KEY_DOWN
+                && keyCode != KEY_LEFT && keyCode != KEY_RIGHT && keyCode != KEY_PAGEDOWN && keyCode != KEY_PAGEUP
+                && keyCode != KEY_ESCAPE) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     /**
      * 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-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorPresenter.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -31,7 +31,6 @@
 import com.calclab.suco.client.events.Listener2;
 import com.calclab.suco.client.ioc.Provider;
 import com.google.gwt.libideas.resources.client.ImageResource;
-import com.xpn.xwiki.wysiwyg.client.dom.Selection;
 
 public class RTEditorPresenter implements RTEditor {
 
@@ -132,6 +131,11 @@
         return canBeExtended();
     }
 
+    public void detach() {
+        topBar.clear();
+        sndBar.clear();
+    }
+
     public void fireOnEdit() {
         onEdit.fire();
     }
@@ -141,7 +145,7 @@
     }
 
     public String getHtml() {
-        return view.getHtml();
+        return view.getHTML();
     }
 
     public ActionToolbar<Object> getSndBar() {
@@ -167,17 +171,12 @@
         palette.hide();
     }
 
-    public void reset() {
-        topBar.clear();
-        sndBar.clear();
-    }
-
     public void setExtended(boolean extended) {
         this.extended = extended;
     }
 
     public void setHtml(String html) {
-        view.setHtml(html);
+        view.setHTML(html);
         view.focus();
     }
 
@@ -404,12 +403,12 @@
                         EditHtmlDialog dialog = editHtmlDialog.get();
                         dialog.setUpdateListener(new Listener<String>() {
                             public void onEvent(String html) {
-                                view.setHtml(html);
+                                view.setHTML(html);
                                 fireOnEdit();
                             }
                         });
                         dialog.show();
-                        dialog.setHtml(view.getHtml());
+                        dialog.setHtml(view.getHTML());
                     }
                 });
         editHtml.setIconCls(getCssName(imgResources.edithtml()));
@@ -661,12 +660,17 @@
                     public void onEvent() {
                         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);
+                                // 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);
                             }
                         });
                     }
@@ -674,7 +678,7 @@
         devInfo.setTextDescription(i18n.t("Developers info"));
         devInfo.setAddCondition(canBeExtended);
         devInfo.setParentMenuTitle(i18n.t(FORMAT_MENU));
-        devInfo.setShortcut(new ActionShortcut(true, false, false, 'I'));
+        devInfo.setShortcut(new ActionShortcut(false, true, false, 'I'));
 
         actions.add(withNoItem(bold));
         actions.add(withNoItem(italic));

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-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/basic/RTEditorView.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -4,8 +4,6 @@
 import org.ourproject.kune.platf.client.actions.ActionItemCollection;
 import org.ourproject.kune.platf.client.ui.rte.RichTextArea.FontSize;
 
-import com.xpn.xwiki.wysiwyg.client.dom.Document;
-
 public interface RTEditorView extends View {
 
     void addActions(ActionItemCollection<Object> actions);
@@ -26,10 +24,8 @@
 
     void focus();
 
-    Document getDocument();
+    String getHTML();
 
-    String getHtml();
-
     String getText();
 
     void insertComment(String author);
@@ -90,7 +86,7 @@
 
     void setForeColor(String color);
 
-    void setHtml(String html);
+    void setHTML(String html);
 
     void setText(String text);
 

Added: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfo.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfo.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfo.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -0,0 +1,63 @@
+package org.ourproject.kune.platf.client.ui.rte.insertlink;
+
+import com.google.gwt.dom.client.Element;
+
+public class LinkInfo {
+
+    private static final String HREF = "href";
+    // private static final String TITLE = "title";
+    private static final String TARGET = "target";
+    private static final String _BLANK = "_blank";
+
+    public static LinkInfo parse(Element element) {
+        String target = element.getAttribute(TARGET);
+        return new LinkInfo(element.getInnerText(), element.getTitle(), element.getAttribute(HREF), target != null
+                && target.equals(_BLANK));
+    }
+
+    private String text;
+    private String title;
+    private String url;
+
+    private boolean inNewWindow;
+
+    public LinkInfo(String text, String title, String url, boolean inNewWindow) {
+        this.text = text;
+        this.title = title;
+        this.url = url;
+        this.inNewWindow = inNewWindow;
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public boolean isInNewWindow() {
+        return inNewWindow;
+    }
+
+    public void setInNewWindow(boolean inNewWindow) {
+        this.inNewWindow = inNewWindow;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+}

Added: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfoTest.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfoTest.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/insertlink/LinkInfoTest.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -0,0 +1,28 @@
+package org.ourproject.kune.platf.client.ui.rte.insertlink;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.ui.Hyperlink;
+
+public class LinkInfoTest extends GWTTestCase {
+
+    private static final String TEXT = "some link";
+    private static final String HREF = "http://example.com";
+    private static final String TITLE = "on over";
+
+    @Override
+    public String getModuleName() {
+        return "org.ourproject.kune.app.Kune";
+    }
+
+    public void testSimpleLink() {
+        Hyperlink link = new Hyperlink(TEXT, HREF);
+        link.setTitle(TITLE);
+        Log.info(link.getHTML());
+        LinkInfo linkParsed = LinkInfo.parse(link.getElement());
+        assertEquals(TEXT, linkParsed.getText());
+        assertEquals(HREF, linkParsed.getUrl());
+        assertEquals(TITLE, linkParsed.getTitle());
+        assertEquals(false, linkParsed.isInNewWindow());
+    }
+}

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditor.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -30,6 +30,8 @@
      */
     BeforeActionListener getBeforeSavingListener();
 
+    boolean isSavePending();
+
     /**
      * Call this when your save action is successful
      */

Modified: trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/platf/client/ui/rte/saving/RTESavingEditorPresenter.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -90,6 +90,10 @@
         this.view = view;
     }
 
+    public boolean isSavePending() {
+        return savePending;
+    }
+
     public void onDoSaveAndClose() {
         saveAndCloseConfirmed = true;
         onDoSave();
@@ -138,7 +142,7 @@
         stateManager.removeBeforeStateChangeListener(beforeStateChangeListener);
         stateManager.resumeTokenChange();
         reset();
-        editor.reset();
+        editor.detach();
         onDoEditCancelled();
     }
 

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/WorkspaceModule.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -82,6 +82,7 @@
 import org.ourproject.kune.workspace.client.entityheader.maxmin.MaxMinWorkspace;
 import org.ourproject.kune.workspace.client.entityheader.maxmin.MaxMinWorkspacePanel;
 import org.ourproject.kune.workspace.client.entityheader.maxmin.MaxMinWorkspacePresenter;
+import org.ourproject.kune.workspace.client.events.GlobalShortcutRegister;
 import org.ourproject.kune.workspace.client.i18n.I18nTranslator;
 import org.ourproject.kune.workspace.client.i18n.I18nTranslatorPanel;
 import org.ourproject.kune.workspace.client.i18n.I18nTranslatorPresenter;
@@ -948,5 +949,13 @@
             }
         });
 
+        register(ApplicationComponentGroup.class, new Factory<GlobalShortcutRegister>(GlobalShortcutRegister.class) {
+            @Override
+            public GlobalShortcutRegister create() {
+                return new GlobalShortcutRegister($(ActionManager.class));
+            }
+        });
+
+        $(GlobalShortcutRegister.class).enable();
     }
 }

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/editor/ContentEditor.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -17,6 +17,8 @@
 
 import com.calclab.suco.client.events.Listener;
 import com.calclab.suco.client.events.Listener0;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.WindowCloseListener;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.gwtext.client.widgets.BoxComponent;
@@ -31,19 +33,31 @@
     private final AbstractToolbar topbar;
     private final SiteSignOutLink siteSignOutLink;
 
-    public ContentEditor(RTEditor editor, boolean autoSave, I18nTranslationService i18n, StateManager stateManager,
-            SiteSignOutLink siteSignOutLink, DeferredCommandWrapper deferredCommandWrapper,
+    public ContentEditor(RTEditor editor, boolean autoSave, final I18nTranslationService i18n,
+            StateManager stateManager, SiteSignOutLink siteSignOutLink, DeferredCommandWrapper deferredCommandWrapper,
             RTEImgResources imgResources, WorkspaceSkeleton ws, TimerWrapper timer, RTESavingEditorView view) {
         super(editor, autoSave, i18n, stateManager, deferredCommandWrapper, imgResources, timer);
         this.siteSignOutLink = siteSignOutLink;
         super.init(view);
         this.ws = ws;
+        Window.addWindowCloseListener(new WindowCloseListener() {
+            public void onWindowClosed() {
+            }
 
+            public String onWindowClosing() {
+                if (isSavePending()) {
+                    return i18n.t("You have changes without save. Are you sure?");
+                }
+                // onDoSaveAndClose();
+                return null;
+            }
+
+        });
         vp = new VerticalPanel();
         basicEditor = super.getBasicEditor();
         vp.add((Widget) ((ActionToolbarPanel<Object>) basicEditor.getSndBar().getView()).getToolbar());
         editorPanel = (RTEditorPanel) basicEditor.getEditorArea();
-        vp.add(editorPanel.getRTE());
+        vp.add(editorPanel);
         basicEditor.setExtended(true);
         vp.setWidth("100%");
         ws.getEntityWorkspace().addContentListener(new ContainerListenerAdapter() {
@@ -81,6 +95,6 @@
         // Log.debug("Sndbar height: " + barHeight + " new height: " +
         // newHeight);
         editorPanel.adjustSize(newHeight);
-        vp.setCellHeight(editorPanel.getRTE(), "" + newHeight);
+        vp.setCellHeight(editorPanel, "" + newHeight);
     }
 }

Added: trunk/src/main/java/org/ourproject/kune/workspace/client/events/GlobalShortcutRegister.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/events/GlobalShortcutRegister.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/events/GlobalShortcutRegister.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -0,0 +1,38 @@
+package org.ourproject.kune.workspace.client.events;
+
+import org.ourproject.kune.platf.client.actions.ActionItem;
+import org.ourproject.kune.platf.client.actions.ActionManager;
+import org.ourproject.kune.platf.client.actions.ActionShortcutRegister;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.EventPreview;
+
+public class GlobalShortcutRegister extends ActionShortcutRegister {
+
+    private final EventPreview eventPreview;
+
+    public GlobalShortcutRegister(final ActionManager actionManager) {
+        eventPreview = new EventPreview() {
+            @SuppressWarnings("unchecked")
+            public boolean onEventPreview(Event event) {
+                ActionItem actionItem = get(event);
+                if (actionItem != null) {
+                    // Log.debug("Not propagating event");
+                    DOM.eventPreventDefault(event);
+                    actionManager.doAction(actionItem);
+                    return false;
+                }
+                return true;
+            }
+        };
+    }
+
+    public void disable() {
+        DOM.removeEventPreview(eventPreview);
+    }
+
+    public void enable() {
+        DOM.addEventPreview(eventPreview);
+    }
+}

Modified: trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/main/java/org/ourproject/kune/workspace/client/hello/HelloWorldModule.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -20,6 +20,7 @@
 package org.ourproject.kune.workspace.client.hello;
 
 import org.ourproject.kune.platf.client.View;
+import org.ourproject.kune.platf.client.actions.ActionShortcut;
 import org.ourproject.kune.platf.client.actions.ActionToolbarMenuDescriptor;
 import org.ourproject.kune.platf.client.dto.AccessRolDTO;
 import org.ourproject.kune.platf.client.dto.UserSimpleDTO;
@@ -27,11 +28,13 @@
 import org.ourproject.kune.platf.client.i18n.I18nTranslationServiceMocked;
 import org.ourproject.kune.platf.client.ui.noti.NotifyUser;
 import org.ourproject.kune.workspace.client.AbstractFoldableContentActions;
+import org.ourproject.kune.workspace.client.events.GlobalShortcutRegister;
 import org.ourproject.kune.workspace.client.skel.WorkspaceSkeleton;
 import org.ourproject.kune.workspace.client.socialnet.UserActionRegistry;
 
 import com.allen_sauer.gwt.log.client.Log;
 import com.calclab.suco.client.events.Listener;
+import com.calclab.suco.client.events.Listener0;
 import com.calclab.suco.client.ioc.Provider;
 import com.calclab.suco.client.ioc.decorator.Singleton;
 import com.calclab.suco.client.ioc.module.AbstractModule;
@@ -202,6 +205,15 @@
             }
         });
 
+        /**
+         * Global shortcut sample definition
+         */
+        $(GlobalShortcutRegister.class).put(new ActionShortcut(false, true, false, 'S'), new Listener0() {
+            public void onEvent() {
+                NotifyUser.info("Global Ctrl+S pressed");
+            }
+        });
+
         // And because nobody use this module, we get the class (to force the
         // creation of the
         // Helloworld instance):

Modified: trunk/src/test/java/org/ourproject/kune/platf/client/actions/ActionShortcutTest.java
===================================================================
--- trunk/src/test/java/org/ourproject/kune/platf/client/actions/ActionShortcutTest.java	2009-03-13 21:36:47 UTC (rev 1075)
+++ trunk/src/test/java/org/ourproject/kune/platf/client/actions/ActionShortcutTest.java	2009-03-15 17:29:41 UTC (rev 1076)
@@ -12,7 +12,7 @@
 
     @Test
     public void altS() {
-        ActionShortcut shortcut = new ActionShortcut(true, false, false, 'S', null);
+        ActionShortcut shortcut = new ActionShortcut(false, true, false, 'S', null);
         assertEquals(" (Alt+S)", shortcut.toString());
         assertTrue(shortcut.is('S', KeyboardListener.MODIFIER_ALT));
         assertTrue(!shortcut.is('S', KeyboardListener.MODIFIER_CTRL));
@@ -52,7 +52,7 @@
 
     @Test
     public void ctrlShiftS() {
-        ActionShortcut shortcut = new ActionShortcut(false, true, true, 'S', null);
+        ActionShortcut shortcut = new ActionShortcut(true, false, true, 'S', null);
         assertEquals(" (Ctrl+Shift+S)", shortcut.toString());
         assertTrue(!shortcut.is('S', KeyboardListener.MODIFIER_ALT));
         assertTrue(shortcut.is('S', KeyboardListener.MODIFIER_SHIFT | KeyboardListener.MODIFIER_CTRL));




More information about the kune-commits mailing list