use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.
the class XfceTrash 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;
}
use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.
the class MainMenuBar method menuSelected.
// ////////////////////////
// MenuListener methods //
// ////////////////////////
public void menuSelected(MenuEvent e) {
Object source = e.getSource();
if (source == viewMenu) {
FileTable activeTable = mainFrame.getActiveTable();
// Select the 'sort by' criterion currently in use in the active table
sortByItems[activeTable.getSortInfo().getCriterion().ordinal()].setSelected(true);
toggleShowFoldersFirstItem.setSelected(activeTable.getSortInfo().getFoldersFirst());
toggleShowHiddenFilesItem.setSelected(MuConfigurations.getPreferences().getVariable(MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES));
toggleTreeItem.setSelected(activeTable.getFolderPanel().isTreeVisible());
toggleToggleAutoSizeItem.setSelected(mainFrame.isAutoSizeColumnsEnabled());
toggleUseSinglePanel.setSelected(mainFrame.isSinglePanel());
/* TODO branch toggleBranchView.setSelected(activeTable.getFolderPanel().isBranchView()); */
} else if (source == columnsMenu) {
// Update the selected and enabled state of each column menu item.
FileTable activeTable = mainFrame.getActiveTable();
for (Column c : Column.values()) {
if (// Name column doesn't have a menu item as it cannot be disabled
c == Column.NAME)
continue;
JCheckBoxMenuItem item = toggleColumnItems[c.ordinal()];
item.setSelected(activeTable.isColumnEnabled(c));
item.setEnabled(activeTable.isColumnDisplayable(c));
// Override the action's label to a shorter one
item.setText(c.getLabel());
}
} else if (source == goMenu) {
// as they might have changed since menu was last selected
for (int i = goMenu.getItemCount(); i > volumeOffset; i--) goMenu.remove(volumeOffset);
AbstractFile[] volumes = LocalFile.getVolumes();
int nbFolders = volumes.length;
for (int i = 0; i < nbFolders; i++) goMenu.add(new OpenLocationAction(mainFrame, new Hashtable<String, Object>(), volumes[i]));
} else if (source == bookmarksMenu) {
// as bookmarks might have changed since menu was last selected
for (int i = bookmarksMenu.getItemCount(); i > bookmarksOffset; i--) bookmarksMenu.remove(bookmarksOffset);
// Add bookmarks menu items
java.util.List<Bookmark> bookmarks = BookmarkManager.getBookmarks();
int nbBookmarks = bookmarks.size();
if (nbBookmarks > 0) {
for (int i = 0; i < nbBookmarks; i++) MenuToolkit.addMenuItem(bookmarksMenu, new OpenLocationAction(mainFrame, new Hashtable<String, Object>(), bookmarks.get(i)), null);
} else {
// Show 'No bookmark' as a disabled menu item instead showing nothing
JMenuItem noBookmarkItem = MenuToolkit.addMenuItem(bookmarksMenu, Translator.get("bookmarks_menu.no_bookmark"), null, null, null);
noBookmarkItem.setEnabled(false);
}
} else if (source == windowMenu) {
// Select the split orientation currently in use
if (mainFrame.getSplitPaneOrientation())
splitVerticallyItem.setSelected(true);
else
splitHorizontallyItem.setSelected(true);
// menu has been deselected.
for (int i = windowMenu.getItemCount(); i > windowOffset; i--) windowMenu.remove(windowOffset);
// This WeakHashMap maps menu items to frame instances. It has to be a weakly referenced hash map
// and not a regular hash map, since it will not (and cannot) be emptied when the menu has been deselected
// and we really do not want this hash map to prevent the frames to be GCed
windowMenuFrames = new WeakHashMap<JMenuItem, Frame>();
// Create a menu item for each of the MainFrame instances, that displays the MainFrame's path
// and a keyboard accelerator to recall the frame (for the first 10 frames only).
java.util.List<MainFrame> mainFrames = WindowManager.getMainFrames();
MainFrame mainFrame;
JCheckBoxMenuItem checkBoxMenuItem;
int nbFrames = mainFrames.size();
for (int i = 0; i < nbFrames; i++) {
mainFrame = mainFrames.get(i);
checkBoxMenuItem = new JCheckBoxMenuItem();
// If frame number is less than 10, use the corresponding action class (accelerator will be displayed in the menu item)
MuAction recallWindowAction;
if (i < 10) {
recallWindowAction = ActionManager.getActionInstance(RECALL_WINDOW_ACTION_IDS[i], this.mainFrame);
} else // Else use the generic RecallWindowAction
{
Hashtable<String, Object> actionProps = new Hashtable<String, Object>();
// Specify the window number using the dedicated property
actionProps.put(RecallWindowAction.WINDOW_NUMBER_PROPERTY_KEY, "" + (i + 1));
recallWindowAction = ActionManager.getActionInstance(new ActionParameters(RecallWindowAction.Descriptor.ACTION_ID, actionProps), this.mainFrame);
}
checkBoxMenuItem.setAction(recallWindowAction);
// Replace the action's label and use the MainFrame's current folder path instead
checkBoxMenuItem.setText((i + 1) + " " + mainFrame.getActiveTable().getFolderPanel().getCurrentFolder().getAbsolutePath());
// Use the action's label as a tooltip
checkBoxMenuItem.setToolTipText(recallWindowAction.getLabel());
// Check current MainFrame (the one this menu bar belongs to)
checkBoxMenuItem.setSelected(mainFrame == this.mainFrame);
windowMenu.add(checkBoxMenuItem);
}
// Add 'other' (non-MainFrame) windows : viewer and editor frames, no associated accelerator
Frame[] frames = Frame.getFrames();
nbFrames = frames.length;
Frame frame;
JMenuItem menuItem;
boolean firstFrame = true;
for (int i = 0; i < nbFrames; i++) {
frame = frames[i];
// Test if Frame is not hidden (disposed), Frame.getFrames() returns both active and disposed frames
if (frame.isShowing() && (frame instanceof FileFrame)) {
// and other frames
if (firstFrame) {
windowMenu.add(new JSeparator());
firstFrame = false;
}
// Use frame's window title
menuItem = new JMenuItem(frame.getTitle());
menuItem.addActionListener(this);
windowMenu.add(menuItem);
windowMenuFrames.put(menuItem, frame);
}
}
} else if (source == themesMenu) {
// Remove all previous theme items, create new ones for each available theme and select the current theme
themesMenu.removeAll();
ButtonGroup buttonGroup = new ButtonGroup();
Iterator<Theme> themes = ThemeManager.availableThemes();
Theme theme;
JCheckBoxMenuItem item;
themesMenu.add(new JMenuItem(new EditCurrentThemeAction()));
themesMenu.add(new JSeparator());
while (themes.hasNext()) {
theme = themes.next();
item = new JCheckBoxMenuItem(new ChangeCurrentThemeAction(theme));
buttonGroup.add(item);
if (ThemeManager.isCurrentTheme(theme))
item.setSelected(true);
themesMenu.add(item);
}
}
}
use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.
the class RecentExecutedFilesQL method acceptListItem.
@Override
protected void acceptListItem(AbstractFile item) {
MainFrame mainFrame = WindowManager.getCurrentMainFrame();
if (item.getURL().getScheme().equals(LocalFile.SCHEMA) && (item.hasAncestor(LocalFile.class))) {
try {
DesktopManager.open(item);
} catch (IOException e) {
}
} else // Copies non-local file in a temporary local file and opens them using their native association.
{
ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying"));
TempExecJob job = new TempExecJob(progressDialog, mainFrame, item);
progressDialog.start(job);
}
}
use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.
the class DefaultMainFramesBuilder method build.
@Override
public Collection<MainFrame> build() {
int nbFrames = snapshot.getIntegerVariable(MuSnapshot.getWindowsCount());
// if last configuration is requested and exists in the snapshot file, restore it
if (nbFrames > 0 && MuConfigurations.getPreferences().getVariable(MuPreference.STARTUP_FOLDERS).equals(MuPreferences.STARTUP_FOLDERS_LAST)) {
return IntStream.range(0, nbFrames).mapToObj(this::createMainFrame).collect(Collectors.toList());
} else {
int index = getSelectedFrame();
MainFrame mainFrame = new MainFrame(new ConfFileTableTab(getInitialPath(FolderPanelType.LEFT)), getFileTableConfiguration(FolderPanelType.LEFT, index), new ConfFileTableTab(getInitialPath(FolderPanelType.RIGHT)), getFileTableConfiguration(FolderPanelType.RIGHT, index));
// if there is no window saved in the snapshot file, use default settings
if (nbFrames == 0) {
mainFrame.setBounds(getDefaultSize());
} else // otherwise, use the settings of the selected window
{
int x = snapshot.getIntegerVariable(MuSnapshot.getX(index));
int y = snapshot.getIntegerVariable(MuSnapshot.getY(index));
int width = snapshot.getIntegerVariable(MuSnapshot.getWidth(index));
int height = snapshot.getIntegerVariable(MuSnapshot.getHeight(index));
mainFrame.setBounds(new Rectangle(x, y, width, height));
}
return Collections.singleton(mainFrame);
}
}
use of com.mucommander.ui.main.MainFrame in project mucommander by mucommander.
the class DefaultMainFramesBuilder method createMainFrame.
private MainFrame createMainFrame(int index) {
int nbTabsInLeftPanel = snapshot.getIntegerVariable(MuSnapshot.getTabsCountVariable(index, true));
ConfFileTableTab[] leftTabs = new ConfFileTableTab[nbTabsInLeftPanel];
for (int i = 0; i < nbTabsInLeftPanel; ++i) leftTabs[i] = new ConfFileTableTab(snapshot.getBooleanVariable(MuSnapshot.getTabLockedVariable(index, true, i)), restoreFileURL(snapshot.getVariable(MuSnapshot.getTabLocationVariable(index, true, i))), snapshot.getVariable(MuSnapshot.getTabTitleVariable(index, true, i)));
int nbTabsInRightPanel = snapshot.getIntegerVariable(MuSnapshot.getTabsCountVariable(index, false));
ConfFileTableTab[] rightTabs = new ConfFileTableTab[nbTabsInRightPanel];
for (int i = 0; i < nbTabsInRightPanel; ++i) rightTabs[i] = new ConfFileTableTab(snapshot.getBooleanVariable(MuSnapshot.getTabLockedVariable(index, false, i)), restoreFileURL(snapshot.getVariable(MuSnapshot.getTabLocationVariable(index, false, i))), snapshot.getVariable(MuSnapshot.getTabTitleVariable(index, false, i)));
MainFrame mainFrame = new MainFrame(leftTabs, getInitialSelectedTab(FolderPanelType.LEFT, index), getFileTableConfiguration(FolderPanelType.LEFT, index), rightTabs, getInitialSelectedTab(FolderPanelType.RIGHT, index), getFileTableConfiguration(FolderPanelType.RIGHT, index));
// Retrieve last saved window bounds
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int x = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.getX(index));
int y = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.getY(index));
int width = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.getWidth(index));
int height = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.getHeight(index));
// Retrieves the last known size of the screen.
int lastScreenWidth = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.SCREEN_WIDTH);
int lastScreenHeight = MuSnapshot.getSnapshot().getIntegerVariable(MuSnapshot.SCREEN_HEIGHT);
// reset the window's dimensions to their default values.
if (x == -1 || y == -1 || width == -1 || height == -1 || screenSize.width != lastScreenWidth || screenSize.height != lastScreenHeight || width + x > screenSize.width + 5 || height + y > screenSize.height + 5) {
// Full screen bounds are not reliable enough, in particular under Linux+Gnome
// so we simply make the initial window 4/5 of screen's size, and center it.
// This should fit under any window manager / platform
x = screenSize.width / 10;
y = screenSize.height / 10;
width = (int) (screenSize.width * 0.8);
height = (int) (screenSize.height * 0.8);
}
mainFrame.setBounds(new Rectangle(x, y, width, height));
// Retrieve the Frame's SinglePanelView toggle state...
if (MuSnapshot.getSnapshot().getBooleanVariable(MuSnapshot.getSinglePanelViewToggleState(index))) {
ActionManager.performAction(ToggleUseSinglePanelAction.Descriptor.ACTION_ID, mainFrame);
}
return mainFrame;
}
Aggregations