Changeset 28


Ignore:
Timestamp:
10/02/02 18:16:19 (20 years ago)
Author:
piso
Message:

shellCommand()

File:
1 edited

Legend:

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

    r2 r28  
    33 *
    44 * Copyright (C) 2000-2002 Peter Graves
    5  * $Id: ShellCommand.java,v 1.1.1.1 2002-09-24 16:08:40 piso Exp $
     5 * $Id: ShellCommand.java,v 1.2 2002-10-02 18:16:19 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    140140        }
    141141    }
     142
     143    public static void shellCommand()
     144    {
     145        if (Platform.isPlatformWindows() && !Platform.isPlatformWindows5())
     146            return;
     147        final Editor editor = Editor.currentEditor();
     148        InputDialog d = new InputDialog(editor, "Command:", "Shell Command", null);
     149        d.setHistory(new History("shellCommand.command"));
     150        editor.centerDialog(d);
     151        d.show();
     152        String command = d.getInput();
     153        if (command == null)
     154            return;
     155        command = command.trim();
     156        if (command.length() == 0)
     157            return;
     158        shellCommand(editor, command);
     159    }
     160
     161    public static void shellCommand(String command)
     162    {
     163        if (Platform.isPlatformWindows() && !Platform.isPlatformWindows5())
     164            return;
     165        shellCommand(Editor.currentEditor(), command);
     166    }
     167
     168    private static void shellCommand(Editor editor, String command)
     169    {
     170        final File dir = editor.getCurrentDirectory();
     171        if (dir == null || !dir.isDirectory())
     172            return;
     173        String cmdline = "(\\cd " + dir.canonicalPath() + " && " + command + ")";
     174        ShellCommand shellCommand = new ShellCommand(cmdline);
     175        shellCommand.run();
     176        String output = shellCommand.getOutput();
     177        if (output != null && output.length() > 0) {
     178            OutputBuffer buf = OutputBuffer.getOutputBuffer(output);
     179            if (buf != null) {
     180                buf.setTitle(command);
     181                editor.makeNext(buf);
     182                editor.activateInOtherWindow(buf);
     183            }
     184        }
     185    }
    142186}
Note: See TracChangeset for help on using the changeset viewer.