~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/browser/browser.js

  • Committer: wagrant
  • Date: 2008-07-14 05:56:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:865
browser: Warn users before running, serving and refreshing if the file
         currently being edited has unsaved changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
 */
182
182
function refresh()
183
183
{
184
 
    navigate(current_path);
 
184
    if (maybe_save('All changes since the last save will be lost!'))
 
185
        navigate(current_path);
185
186
}
186
187
 
187
188
/** Determines the "handler type" from a MIME type.
373
374
    dom_removechildren(document.getElementById("filesbody"));
374
375
}
375
376
 
 
377
/* Checks if a file needs to be saved. If it does, the user will be asked
 
378
 * if they want to continue anyway. The caller must specify a warning
 
379
 * sentence which indicates the consequences of continuing.
 
380
 * Returns true if we should continue, and false if we should not.
 
381
 */
 
382
function maybe_save(warning)
 
383
{
 
384
    if (warning == null) warning = '';
 
385
    if (current_file.isdir) return true;
 
386
    if (document.getElementById("save_button").disabled) return true;
 
387
    return confirm("This file has unsaved changes. " + warning +
 
388
                   "\nAre you sure you wish to continue?");
 
389
}
 
390
 
376
391
/** Deletes all "dynamic" content on the page necessary to navigate from
377
392
 * one directory listing to another (does not clear as much as clearpage
378
393
 * does).
550
565
    if (numsel <= 1 && !file.isdir)
551
566
    {
552
567
        serve.setAttribute("class", "choice");
 
568
        serve.setAttribute("onclick",
 
569
              "return maybe_save('The last saved version will be served.')");
553
570
        if (numsel == 0)
554
571
            serve.setAttribute("href",
555
572
                app_path(serve_app, current_path));
561
578
    {
562
579
        serve.setAttribute("class", "disabled");
563
580
        serve.removeAttribute("href");
 
581
        serve.removeAttribute("onclick");
564
582
    }
565
583
 
566
584
    /* Run */
806
824
 */
807
825
function runfile(localpath)
808
826
{
 
827
    if (!maybe_save('The last saved version will be run.')) return false;
 
828
 
809
829
    /* Dump the entire file to the console */
810
830
    var callback = function()
811
831
    {