Search in sources :

Example 6 with MainFrame

use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.

the class ActionKeymap method registerActionAccelerators.

/**
 * Register primary and alternative accelerators to MuAction.
 */
private static void registerActionAccelerators(String actionId, KeyStroke accelerator, KeyStroke alternateAccelerator) {
    // If accelerator is null, replace it with alternateAccelerator
    if (accelerator == null) {
        accelerator = alternateAccelerator;
        alternateAccelerator = null;
    }
    // New accelerators are identical to the default action's accelerators
    if (equals(accelerator, ActionProperties.getDefaultAccelerator(actionId)) && equals(alternateAccelerator, ActionProperties.getDefaultAlternativeAccelerator(actionId))) {
        // Remove all action's accelerators customization
        customPrimaryActionKeymap.remove(actionId);
        customAlternateActionKeymap.remove(actionId);
        acceleratorMap.remove(accelerator);
        acceleratorMap.remove(alternateAccelerator);
    } else // New accelerators are different from the default accelerators
    {
        customPrimaryActionKeymap.put(actionId, accelerator);
        acceleratorMap.putAccelerator(accelerator, actionId);
        customAlternateActionKeymap.put(actionId, alternateAccelerator);
        acceleratorMap.putAlternativeAccelerator(alternateAccelerator, actionId);
    }
    // Update each MainFrame's action instance and input map
    for (MuAction action : ActionManager.getActionInstances(actionId)) {
        MainFrame mainFrame = action.getMainFrame();
        // Remove action from MainFrame's action and input maps
        unregisterAction(mainFrame, action);
        // Change action's accelerators
        action.setAccelerator(accelerator);
        action.setAlternateAccelerator(alternateAccelerator);
        // Add updated action to MainFrame's action and input maps
        registerAction(mainFrame, action);
    }
}
Also used : MainFrame(com.mucommander.ui.main.MainFrame)

Example 7 with MainFrame

use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.

the class BringAllToFrontAction method performAction.

@Override
public void performAction() {
    List<MainFrame> mainFrames = WindowManager.getMainFrames();
    MainFrame currentMainFrame = WindowManager.getCurrentMainFrame();
    int nbMainFrames = mainFrames.size();
    MainFrame mainFrame;
    for (int i = nbMainFrames - 1; i >= 0; i--) {
        mainFrame = mainFrames.get(i);
        if (mainFrame != currentMainFrame) {
            mainFrame.toFront();
        }
    }
    currentMainFrame.toFront();
}
Also used : MainFrame(com.mucommander.ui.main.MainFrame)

Example 8 with MainFrame

use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.

the class GnomeTrash method empty.

/**
 * Empty the trash
 * <p>
 * <b>Implementation notes:</b><br>
 * Simply free the <code>TRASH_PATH</code> directory
 * </p>
 *
 * @return True if everything went well
 */
@Override
public boolean empty() {
    // Abort if there is no usable trash folder
    if (TRASH_FOLDER == null)
        return false;
    FileSet filesToDelete = new FileSet(TRASH_FOLDER);
    try {
        // delete real files
        filesToDelete.addAll(TRASH_FILES_SUBFOLDER.ls());
        // delete spec files
        filesToDelete.addAll(TRASH_INFO_SUBFOLDER.ls());
    } catch (java.io.IOException ex) {
        LOGGER.debug("Failed to list files", ex);
        return false;
    }
    if (filesToDelete.size() > 0) {
        // Starts deleting files
        MainFrame mainFrame = WindowManager.getCurrentMainFrame();
        ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("delete_dialog.deleting"));
        DeleteJob deleteJob = new DeleteJob(progressDialog, mainFrame, filesToDelete, false);
        progressDialog.start(deleteJob);
    }
    return true;
}
Also used : DeleteJob(com.mucommander.job.impl.DeleteJob) FileSet(com.mucommander.commons.file.util.FileSet) IOException(java.io.IOException) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) MainFrame(com.mucommander.ui.main.MainFrame)

Example 9 with MainFrame

use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.

the class StressTester method run.

public void run() {
    Random random = new Random();
    MainFrame mainFrame = WindowManager.getCurrentMainFrame();
    while (run) {
        if (random.nextInt(2) == 0)
            ActionManager.performAction(com.mucommander.ui.action.impl.SwitchActiveTableAction.Descriptor.ACTION_ID, mainFrame);
        FolderPanel folderPanel = mainFrame.getActivePanel();
        FileTable fileTable = mainFrame.getActiveTable();
        AbstractFile currentFolder = folderPanel.getCurrentFolder();
        try {
            AbstractFile parentFolder = currentFolder.getParent();
            AbstractFile[] children = currentFolder.ls();
            // 1 in 3 chance to go up if folder has children
            if (children.length == 0 || (random.nextInt(3) == 0 && parentFolder != null)) {
                fileTable.selectRow(0);
                ActionManager.performAction(com.mucommander.ui.action.impl.OpenAction.Descriptor.ACTION_ID, mainFrame);
            } else {
                AbstractFile randomChild = children[random.nextInt(children.length)];
                if (!randomChild.isBrowsable())
                    continue;
                // Try to ls() in RandomChild to trigger an IOException if folder is not readable
                // so that no error dialog pops up when calling tryChangeCurrentFolder()
                randomChild.ls();
                fileTable.selectFile(randomChild);
                ActionManager.performAction(com.mucommander.ui.action.impl.OpenAction.Descriptor.ACTION_ID, mainFrame);
            // folderPanel.tryChangeCurrentFolder(randomChild, true);
            }
        } catch (Exception e) {
            LOGGER.debug("Caught Exception", e);
        }
        LOGGER.trace("Sleeping for a bit...");
        try {
            Thread.sleep(100 + random.nextInt(200));
        } catch (InterruptedException e) {
            LOGGER.debug("Caught InterruptedException", e);
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) Random(java.util.Random) FileTable(com.mucommander.ui.main.table.FileTable) MainFrame(com.mucommander.ui.main.MainFrame) FolderPanel(com.mucommander.ui.main.FolderPanel) IOException(java.io.IOException)

Example 10 with MainFrame

use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.

the class Activator method createCoreService.

private CoreService createCoreService() {
    return new CoreService() {

        @Override
        public void showAbout() {
            MainFrame mainFrame = WindowManager.getCurrentMainFrame();
            // Do nothing (return) when in 'no events mode'
            if (mainFrame.getNoEventsMode())
                return;
            new AboutDialog(mainFrame).showDialog();
        }

        @Override
        public void showPreferences() {
            MainFrame mainFrame = WindowManager.getCurrentMainFrame();
            // Do nothing (return) when in 'no events mode'
            if (mainFrame.getNoEventsMode())
                return;
            ActionManager.performAction(com.mucommander.ui.action.impl.ShowPreferencesAction.Descriptor.ACTION_ID, mainFrame);
        }

        @Override
        public boolean doQuit() {
            // Ask the user for confirmation and abort if user refused to quit.
            if (!QuitDialog.confirmQuit())
                return false;
            // We got a green -> quit!
            Application.initiateShutdown();
            return true;
        }

        @Override
        public void openFile(String path) {
            // Wait until the application has been launched. This step is required to properly handle the case where the
            // application is launched with a file to open, for instance when drag-n-dropping a file to the Dock icon
            // when muCommander is not started yet. In this case, this method is called while Launcher is still busy
            // launching the application (no mainframe exists yet).
            Application.waitUntilLaunched();
            AbstractFile file = FileFactory.getFile(path);
            FolderPanel activePanel = WindowManager.getCurrentMainFrame().getActivePanel();
            if (file.isBrowsable())
                activePanel.tryChangeCurrentFolder(file);
            else
                activePanel.tryChangeCurrentFolder(file.getParent(), file, false);
        }
    };
}
Also used : AboutDialog(com.mucommander.ui.dialog.about.AboutDialog) AbstractFile(com.mucommander.commons.file.AbstractFile) CoreService(com.mucommander.os.api.CoreService) MainFrame(com.mucommander.ui.main.MainFrame) FolderPanel(com.mucommander.ui.main.FolderPanel)

Aggregations

MainFrame (com.mucommander.ui.main.MainFrame)13 AbstractFile (com.mucommander.commons.file.AbstractFile)4 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)4 IOException (java.io.IOException)4 FileSet (com.mucommander.commons.file.util.FileSet)3 ConfFileTableTab (com.mucommander.ui.main.tabs.ConfFileTableTab)3 Rectangle (java.awt.Rectangle)3 DeleteJob (com.mucommander.job.impl.DeleteJob)2 FolderPanel (com.mucommander.ui.main.FolderPanel)2 FileTable (com.mucommander.ui.main.table.FileTable)2 Dimension (java.awt.Dimension)2 CopyJob (com.mucommander.job.impl.CopyJob)1 MoveJob (com.mucommander.job.impl.MoveJob)1 TempExecJob (com.mucommander.job.impl.TempExecJob)1 CoreService (com.mucommander.os.api.CoreService)1 ActionParameters (com.mucommander.ui.action.ActionParameters)1 MuAction (com.mucommander.ui.action.MuAction)1 OpenLocationAction (com.mucommander.ui.action.impl.OpenLocationAction)1 AboutDialog (com.mucommander.ui.dialog.about.AboutDialog)1 Column (com.mucommander.ui.main.table.Column)1