[brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - new RecentDocuments, etc. on 2012-05-10 02:48 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Thu, 10 May 2012 02:48:20 +0000

Revision: d204343e12fd
Author:   John Boyer <john.boyer@xxxxxxxxxxxxxxxxx>
Date:     Wed May  9 19:47:26 2012
Log:      new RecentDocuments, etc.
http://code.google.com/p/brailleblaster/source/detail?r=d204343e12fd

Modified:
 /src/main/org/brailleblaster/wordprocessor/DocumentManager.java
 /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java
 /src/main/org/brailleblaster/wordprocessor/WP.java
 /src/main/org/brailleblaster/wordprocessor/WPManager.java

=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Fri May 4 09:34:43 2012 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Wed May 9 19:47:26 2012
@@ -94,7 +94,9 @@
     boolean finished = false;
     private volatile boolean stopRequested = false;
     static final boolean[] flags = new boolean[WPManager.getMaxNumDocs()];
-
+ //static final String[] runningFiles = new String[WPManager.getMaxNumDocs()];
+    static String recentFileName = null;
+    static int recentFileNameIndex = -1;

     /**
      * Constructor that sets things up for a new document.
@@ -140,7 +142,7 @@
         }
         if (action == WP.OpenDocumentGetFile) {
             fileOpen();
-        } else if (action == WP.DocumentFromCommandLine) {
+ } else if ((action == WP.DocumentFromCommandLine)||(action == WP.OpenDocumentGetRecent)) {
             openDocument(documentName);
         }
         boolean stop = false;
@@ -252,7 +254,6 @@
     int numChars;

     void fileOpen () {
-        //        if (BBIni.debugging() && doc != null) {
         if (doc != null){
             returnReason = WP.OpenDocumentGetFile;
             flags[documentNumber] = true;
@@ -271,7 +272,26 @@
         }
         openDocument (documentName);
     }
-
+
+    void recentOpen(String path){
+        if (doc != null){
+ //see if this recent document is already opened in current windows set
+            recentFileNameIndex = WPManager.isRunning(path);
+            if(recentFileNameIndex!= -1){
+                returnReason = WP.SwitchDocuments;
+                flags[documentNumber] = true;
+                return;
+            }
+            recentFileName = path;
+            returnReason = WP.OpenDocumentGetRecent;
+            flags[documentNumber] = true;
+            return;
+        }
+        documentName = path;
+        openDocument (documentName);
+    }
+
+
     void openDocument (String fileName) {
         Builder parser = new Builder();
         try {
@@ -479,6 +499,10 @@
     static void printflags(){
         for(boolean b:flags)    System.out.print (b+", ");
     }
+
+    static String getRecentFileName(){
+        return recentFileName;
+    }

 }

=======================================
--- /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Fri May 4 09:34:43 2012 +++ /src/main/org/brailleblaster/wordprocessor/RecentDocuments.java Wed May 9 19:47:26 2012
@@ -43,6 +43,7 @@
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Combo;
@@ -83,19 +84,20 @@
         shell.setLayout (gridLayout);
         combo = new Combo (shell, SWT.DROP_DOWN|SWT.READ_ONLY);
         combo.setItems(recentDocsArr);
-        combo.setText("Test");
         GridData data = new GridData ();
         data.minimumWidth = 300;
         data.grabExcessHorizontalSpace = true;
         combo.setLayoutData(data);
-        combo.addSelectionListener(new SelectionAdapter() {
+        Button open = new Button(shell, SWT.PUSH);
+        shell.setDefaultButton(open);
+        open.setText("&Open");
+        open.addSelectionListener(new SelectionAdapter() {
             public void widgetSelected(SelectionEvent e) {
                 int key = combo.getSelectionIndex();
-                String value = combo.getText();
+                if(key != -1){
                 String path = recentDocsList.get(key);
-                //This is for debug
-                new Notify("Value="+value+", path="+path);
-                dm.openDocument (path);
+                dm.recentOpen (path);
+                }
                 shell.close();
             }
         });
=======================================
--- /src/main/org/brailleblaster/wordprocessor/WP.java Wed Oct 5 02:48:38 2011 +++ /src/main/org/brailleblaster/wordprocessor/WP.java Wed May 9 19:47:26 2012
@@ -44,6 +44,8 @@
 static final int DocumentFromCommandLine = 5;
 static final int DocumentClosed = 6;
 static final int BBClosed = 7;
+static final int OpenDocumentGetRecent = 8;
+static final int SwitchToRecentDoc = 9;

 // Help

=======================================
--- /src/main/org/brailleblaster/wordprocessor/WPManager.java Fri May 4 01:12:16 2012 +++ /src/main/org/brailleblaster/wordprocessor/WPManager.java Wed May 9 19:47:26 2012
@@ -86,10 +86,15 @@
                 WPManager.resumeAll(documentIndex);
                 break;
             case WP.SwitchDocuments://4
-                //
- System.out.println("Swithcing...from "+ documentIndex+ "to" +getNextAvailableDoc() );
-                documentIndex = getNextAvailableDoc();
+                if(DocumentManager.recentFileNameIndex != -1){
+                    documentIndex = DocumentManager.recentFileNameIndex;
+                    DocumentManager.recentFileNameIndex = -1;
+                }
+                else {
+                    documentIndex = getNextAvailableDoc();
+                }
                 curDoc = documents[documentIndex];
+ //System.out.println("Swithcing...from "+ documentIndex+ "to" +getNextAvailableDoc() );
                 curDoc.resume();
                 break;
             case WP.NewDocument://1
@@ -104,7 +109,7 @@
                 break;
             case WP.OpenDocumentGetFile://2
                 if (getNextAvailablePos() == -1){
-                    new Notify ("Too many documents");
+                    new Notify ("Too many documents to open a new file");
                     curDoc.resume();
                     break;
                 }
@@ -112,6 +117,17 @@
curDoc = documents[documentIndex] = new DocumentManager(display,
                         documentIndex, WP.OpenDocumentGetFile, fileName);
                 break;
+ case WP.OpenDocumentGetRecent://8 open a recent doc in a new windows
+                if (getNextAvailablePos() == -1){
+ new Notify ("Too many documents to open the recent document in a new window");
+                    curDoc.resume();
+                    break;
+                }
+                documentIndex = getNextAvailablePos();
+                fileName = DocumentManager.getRecentFileName();
+ curDoc = documents[documentIndex] = new DocumentManager(display,
+                        documentIndex, WP.OpenDocumentGetRecent, fileName);
+                break;
             case WP.BBClosed://7
                 while(getNextAvailableDoc()!= -1){
                     documents[getNextAvailableDoc()].finish();
@@ -169,6 +185,24 @@
         //if no availabe doc
         return -1;
     }
+
+ //check if a document named fileName is running, return its index or -1;
+    static int isRunning(String fileName){
+        int start = documentIndex;
+        for(int i = 0; i <MAX_NUM_DOCS; i++){
+            if( documents[i] != null){
+                if(documents[i].isFinished()){
+                    documents[i] = null;
+                }
+                else{
+ //System.out.println("isRunning: NO"+i+"'s name is "+documents[i].documentName);
+                    if (documents[i].documentName.equals(fileName))
+                        return i;
+                }
+            }
+        }
+        return -1;
+    }

     int getNextAvailablePos(){
//see if there is available postion for one more document, -1 if it is full
@@ -207,4 +241,5 @@
     static int getMaxNumDocs(){
         return MAX_NUM_DOCS;
     }
-}
+
+}

Other related posts:

  • » [brailleblaster] push by john.bo...@xxxxxxxxxxxxxxxxx - new RecentDocuments, etc. on 2012-05-10 02:48 GMT - brailleblaster