Changeset 64


Ignore:
Timestamp:
05/16/08 14:15:11 (16 years ago)
Author:
ra33
Message:

DeleteFrameset now moves frames into a trash directory... this is to pretect users from accidentally removing them!
They must be restored manually through the file system

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r50 r64  
    218218                if (testsFailed > 0)
    219219                        FrameGraphics.DisplayMessage("Failed: " + testsFailed, Color.RED);
     220                //Remove items from the cursor...
     221                Frame.FreeItems.clear();
    220222        }
    221223
  • trunk/src/org/expeditee/gui/FrameIO.java

    r25 r64  
    4040                PARENT_FOLDER = newFolder;
    4141                FRAME_PATH = PARENT_FOLDER + "framesets" + File.separator;
     42                TRASH_PATH = PARENT_FOLDER + "trash" + File.separator;
    4243                IMAGES_PATH = PARENT_FOLDER + "images" + File.separator;
    4344                HELP_PATH = PARENT_FOLDER + "help" + File.separator;
     
    5253         * subdirectory in this directory.
    5354         */
     55
     56        public static String TRASH_PATH;
    5457
    5558        public static String PARENT_FOLDER;
     
    477480                // disable caching of 0 frames
    478481                SuspendCache();
    479                
     482
    480483                Frame template = null;
    481484                if (templateFrame == null)
     
    757760        }
    758761
    759        
    760        
    761762        public static String ConvertToValidFramesetName(String toValidate) {
    762                 assert(toValidate != null && toValidate.length() > 0);
    763                
     763                assert (toValidate != null && toValidate.length() > 0);
     764
    764765                StringBuffer result = new StringBuffer();
    765766
    766                 if (Character.isDigit(toValidate.charAt(0))){
     767                if (Character.isDigit(toValidate.charAt(0))) {
    767768                        result.append(FRAME_NAME_LAST_CHAR);
    768769                }
    769                
     770
    770771                boolean capital = false;
    771                 for (int i = 0; i < toValidate.length() && result.length() < MAX_NAME_LENGTH; i++) {
     772                for (int i = 0; i < toValidate.length()
     773                                && result.length() < MAX_NAME_LENGTH; i++) {
    772774                        char cur = toValidate.charAt(i);
    773775
     
    785787                assert (result.length() > 0);
    786788                int lastCharIndex = result.length() - 1;
    787                 if (!Character.isLetter(result.charAt(lastCharIndex))){
    788                         if (lastCharIndex ==  MAX_NAME_LENGTH - 1)
    789                                 result.setCharAt(lastCharIndex,FRAME_NAME_LAST_CHAR);
     789                if (!Character.isLetter(result.charAt(lastCharIndex))) {
     790                        if (lastCharIndex == MAX_NAME_LENGTH - 1)
     791                                result.setCharAt(lastCharIndex, FRAME_NAME_LAST_CHAR);
    790792                        else
    791793                                result.append(FRAME_NAME_LAST_CHAR);
    792794                }
    793                
    794                 assert(IsValidFramesetName(result.toString()));
     795
     796                assert (IsValidFramesetName(result.toString()));
    795797                return result.toString();
    796798        }
     
    957959         * letter and contain only letters and digits in between.
    958960         *
    959          * @param frameset the name to be tested
     961         * @param frameset
     962         *            the name to be tested
    960963         * @return true if the frameset name is valid
    961964         */
     
    964967                        return false;
    965968                }
    966                
     969
    967970                int nameLength = frameset.length();
    968                 if( frameset.length() <= 0 || nameLength > MAX_NAME_LENGTH){
     971                if (frameset.length() <= 0 || nameLength > MAX_NAME_LENGTH) {
    969972                        return false;
    970973                }
    971                
    972                 int lastCharIndex = nameLength- 1;
    973                
    974                 if (!Character.isLetter(frameset.charAt(0)) ||
    975                                 !Character.isLetter(frameset.charAt(lastCharIndex)))
     974
     975                int lastCharIndex = nameLength - 1;
     976
     977                if (!Character.isLetter(frameset.charAt(0))
     978                                || !Character.isLetter(frameset.charAt(lastCharIndex)))
    976979                        return false;
    977980
     
    987990                if (!FrameIO.DoesFramesetExist(framesetName))
    988991                        return false;
    989 
     992                // Search all the available directories for the directory
    990993                for (String path : UserSettings.FrameDirs) {
    991994                        String source = path + framesetName.toLowerCase() + File.separator;
    992995                        File framesetDirectory = new File(source);
     996                        // Once we have found the directory move it to the trash
    993997                        if (framesetDirectory.exists()) {
    994                                 for (File f : framesetDirectory.listFiles())
    995                                         f.delete();
    996                                 return framesetDirectory.delete();
     998                                String destPath = FrameIO.TRASH_PATH
     999                                                + framesetName.toLowerCase();
     1000                                int copyNumber = 1;
     1001                                File dest = new File(destPath + File.separator);
     1002                                //Create the trash folder if it doesnt already exist
     1003                                if (!dest.getParentFile().exists())
     1004                                        dest.mkdirs();
     1005                                // If a frameset with the same name is already in the trash add
     1006                                // a number to the end
     1007                                while (dest.exists()) {
     1008                                        dest = new File(destPath + ++copyNumber + File.separator );
     1009                                }
     1010                                return framesetDirectory.renameTo(dest);
    9971011                        }
    9981012                }
Note: See TracChangeset for help on using the changeset viewer.