Changeset 205


Ignore:
Timestamp:
11/05/02 15:22:13 (21 years ago)
Author:
piso
Message:

_submit(): offer to save modified buffers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/P4.java

    r134 r205  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: P4.java,v 1.2 2002-10-14 16:29:33 piso Exp $
     5 * $Id: P4.java,v 1.3 2002-11-05 15:22:13 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2525import gnu.regexp.REMatch;
    2626import gnu.regexp.UncheckedRE;
     27import java.util.ArrayList;
    2728import java.util.Iterator;
    2829import java.util.List;
     
    464465        final String title = sb.toString();
    465466        boolean save = false;
    466         if (parentBuffer.isModified()) {
     467        List list = getModifiedBuffers();
     468        if (list != null && list.size() > 0) {
    467469            int response =
    468470                ConfirmDialog.showConfirmDialogWithCancelButton(editor,
    469                     VC_CHECK_SAVE_PROMPT, title);
     471                    "Save modified buffers first?", title);
    470472            switch (response) {
    471473                case RESPONSE_YES:
     
    479481            editor.repaintNow();
    480482        }
    481         if (!save || parentBuffer.save()) {
     483        if (!save || saveModifiedBuffers(editor, list)) {
    482484            // Look for existing checkin buffer before making a new one.
    483485            CheckinBuffer checkinBuffer = null;
     
    519521        }
    520522    }
    521 
     523   
     524    private static List getModifiedBuffers()
     525    {
     526        ArrayList list = null;
     527        for (BufferIterator it = new BufferIterator(); it.hasNext();) {
     528            Buffer buf = it.nextBuffer();
     529            if (!buf.isModified())
     530                continue;
     531            if (buf.isUntitled())
     532                continue;
     533            final int modeId = buf.getModeId();
     534            if (modeId == SEND_MAIL_MODE)
     535                continue;
     536            if (modeId == CHECKIN_MODE)
     537                continue;
     538            if (buf.getFile() != null && buf.getFile().isLocal()) {
     539                if (list == null)
     540                    list = new ArrayList();
     541                list.add(buf);
     542            }
     543        }
     544        return list;
     545    }
     546
     547    private static boolean saveModifiedBuffers(Editor editor, List list)
     548    {
     549        editor.setWaitCursor();
     550        int numErrors = 0;
     551        for (Iterator it = list.iterator(); it.hasNext();) {
     552            Buffer buf = (Buffer) it.next();
     553            if (buf.getFile() != null && buf.getFile().isLocal()) {
     554                editor.status("Saving modified buffers...");
     555                if (buf.getBooleanProperty(Property.REMOVE_TRAILING_WHITESPACE))
     556                    buf.removeTrailingWhitespace();
     557                if (!buf.save())
     558                    ++numErrors;
     559            }
     560        }
     561        editor.setDefaultCursor();
     562        if (numErrors == 0) {
     563            editor.status("Saving modified buffers...done");
     564            return true;
     565        }
     566        // User will already have seen detailed error information from Buffer.save().
     567        editor.status("");
     568        return false;
     569    }
     570   
    522571    public static void replaceComment(final Editor editor, final String comment)
    523572    {
Note: See TracChangeset for help on using the changeset viewer.