Method: Ruber::MainWindow#save_documents

Defined in:
lib/ruber/main_window/main_window.rb

#save_documents(docs = nil) ⇒ Boolean

Asks the user to save multiple documents

This method is meant to be called in situation where the user may want to save a number of documents, for example when the application is quitting, as it avoids displaying a dialog box for each modified document.

It displays a dialog where the user can choose, among the documents passed as first argument, which ones he wants to save. The user has three choiches:

  • save some (or all) the files, then proceed with the operation which has caused

the dialog to be shown (for example, quitting the application)

  • don’t save any file and go on with the operation

  • abort the operation.

In the first case, this method attempts to perform save the selected files. If any of them can’t be saved, the dialog to choose the files to save will be displayed again, with only those files which couldn’t be saved (after informing the user of the failure). The user can again chose which of those files this method should attempt to save again, or whether to abort the operation or skip saving. This will be repeated until all files have been saved or the user gives up

In the second and third cases, the method simply returns respectively true or false.

Parameters:

  • docs (Array<Document>) (defaults to: nil)

    the list of documents to save. If any document isn’t modified, it’ll be ignored. If no document is mdified, nothing will be done

Returns:

  • (Boolean)

    true if the operation which caused the dialog to be shown can be carried on and false if the user chose to abort it



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/ruber/main_window/main_window.rb', line 540

def save_documents docs = nil
  docs ||= Ruber[:world].documents
  to_save = docs.select{|d| d.modified?}
  until to_save.empty?
    dlg = SaveModifiedFilesDlg.new to_save, self
    to_save = dlg.to_save
    case dlg.exec
    when KDE::Dialog::Yes
      to_save.delete_if{|doc| doc.save}
      unless to_save.empty?
        msg = "The following documents couldn't be saved: #{to_save.join "\n"}\nPlease, choose how to proceed"
        KDE::MessageBox.sorry nil, KDE.i18n(msg)
      end
    when KDE::Dialog::No then to_save.clear
    when Qt::Dialog::Rejected then return false
    end
  end
  true
end