Search in sources :

Example 6 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class BookmarkFile method renameTo.

// - Bookmark renaming -----------------------------------------------------
// -------------------------------------------------------------------------
/**
 * Attempts to rename the bookmark to the specified destination.
 * The operation will only be carried out if the specified destination is a <code>BookmarkFile</code> or has an
 * ancestor that is.
 *
 * @param  destination where to move the bookmark to.
 * @throws IOException if the operation could not be carried out.
 */
@Override
public void renameTo(AbstractFile destination) throws IOException {
    checkRenamePrerequisites(destination, true, true);
    Bookmark oldBookmark;
    Bookmark newBookmark;
    destination = destination.getTopAncestor();
    // Makes sure we're working with a bookmark.
    if (!(destination instanceof BookmarkFile))
        throw new IOException();
    // Creates the new bookmark and checks for conflicts.
    newBookmark = new Bookmark(destination.getName(), bookmark.getLocation());
    if ((oldBookmark = BookmarkManager.getBookmark(newBookmark.getName())) != null)
        BookmarkManager.removeBookmark(oldBookmark);
    // Adds the new bookmark and deletes its 'old' version.
    BookmarkManager.addBookmark(newBookmark);
    BookmarkManager.removeBookmark(bookmark);
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Example 7 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class EditBookmarksDialog method updateComponents.

/**
 * Updates text fields and buttons' enabled state based on the current selection. Should be called
 * whenever the list selection has changed.
 */
private void updateComponents() {
    String nameValue = null;
    String locationValue = null;
    boolean componentsEnabled = false;
    if (!bookmarkList.isSelectionEmpty() && bookmarks.size() > 0) {
        componentsEnabled = true;
        Bookmark b = (Bookmark) bookmarkList.getSelectedValue();
        nameValue = b.getName();
        locationValue = b.getLocation();
    }
    // Ignore text field events while setting values
    ignoreDocumentListenerEvents = true;
    nameField.setText(nameValue);
    nameField.setEnabled(componentsEnabled);
    locationField.setText(locationValue);
    locationField.setEnabled(componentsEnabled);
    ignoreDocumentListenerEvents = false;
    goToButton.setEnabled(componentsEnabled);
    duplicateButton.setEnabled(componentsEnabled);
    removeButton.setEnabled(componentsEnabled);
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Example 8 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class EditBookmarksDialog method modifyBookmark.

/**
 * Called whenever a value in one of the text fields has been modified, and updates the current Bookmark instance to
 * use the new value.
 *
 * @param sourceDocument the javax.swing.text.Document of the JTextField that was modified
 */
private void modifyBookmark(Document sourceDocument) {
    if (ignoreDocumentListenerEvents || bookmarks.size() == 0)
        return;
    int selectedIndex = bookmarkList.getSelectedIndex();
    // Make sure that the selected index is not out of bounds
    if (!bookmarkList.isIndexValid(selectedIndex))
        return;
    Bookmark selectedBookmark = bookmarks.elementAt(selectedIndex);
    if (currentBookmarkSave == null) {
        // is cancelled.
        try {
            currentBookmarkSave = (Bookmark) selectedBookmark.clone();
        } catch (CloneNotSupportedException ex) {
        }
        this.currentListIndex = selectedIndex;
    }
    // Update name
    if (sourceDocument == nameField.getDocument()) {
        String name = nameField.getText();
        if (name.trim().equals(""))
            name = getFreeNameVariation(Translator.get("untitled"));
        selectedBookmark.setName(name);
        bookmarkList.itemModified(selectedIndex, false);
    } else // Update location
    {
        selectedBookmark.setLocation(locationField.getText());
    }
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Example 9 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class BookmarkOutputStream method addBookmark.

/**
 * Adds the specified bookmark to the bookmark manager
 * <p>
 * Note that this method will remove any previous bookmark of the same name.
 * </p>
 * @param name     name of the new bookmark.
 * @param location location of the new bookmark.
 */
public void addBookmark(String name, String location) {
    // Old bookmark of the same name, if any.
    Bookmark oldBookmark;
    // Bookmark to create.
    Bookmark newBookmark;
    // Creates the new bookmark and checks for conflicts.
    newBookmark = new Bookmark(name, location);
    if ((oldBookmark = BookmarkManager.getBookmark(name)) != null)
        BookmarkManager.removeBookmark(oldBookmark);
    // Adds the new bookmark.
    BookmarkManager.addBookmark(newBookmark);
}
Also used : Bookmark(com.mucommander.bookmark.Bookmark)

Example 10 with Bookmark

use of com.mucommander.bookmark.Bookmark in project mucommander by mucommander.

the class LocationTextField method textFieldValidated.

/**
 * @return true if a malformed url was entered, false otherwise.
 */
public boolean textFieldValidated() {
    String location = getText();
    // Mucommander should in theory be able to access such files without any problem but this hasn't been tested.
    if (OsFamily.WINDOWS.isCurrent() && location.indexOf(":\\") == 1) {
        // Looks for trailing spaces and if some
        Matcher matcher = windowsTrailingSpacePattern.matcher(location);
        if (matcher.find())
            location = location.substring(0, matcher.start());
    }
    // Save the path that was entered in case the location change fails or is cancelled
    locationFieldTextSave = location;
    // Indicate we search for location corresponding to the given string.
    // it will be false we'll find one.
    boolean tryToInterpretEnteredString = true;
    // Look for a bookmark which name is the entered string (case insensitive)
    Bookmark b = BookmarkManager.getBookmark(location);
    if (b != null) {
        // Change the current folder to the bookmark's location
        setText(location = b.getLocation());
        tryToInterpretEnteredString = false;
    }
    // Look for a volume whose name is the entered string (case insensitive)
    AbstractFile[] volumes = LocalFile.getVolumes();
    for (int i = 0; tryToInterpretEnteredString && i < volumes.length; i++) {
        if (volumes[i].getName().equalsIgnoreCase(location)) {
            // Change the current folder to the volume folder
            setText(location = volumes[i].getAbsolutePath());
            tryToInterpretEnteredString = false;
        }
    }
    // Look for a system variable which name is the entered string (case insensitive)
    if (tryToInterpretEnteredString && location.startsWith("$")) {
        String variableKey = location.substring(1);
        String variableValue = System.getenv(variableKey);
        if (variableValue != null)
            setText(location = variableValue);
    }
    // Remember that the folder change was initiated by the location field
    folderChangeInitiatedByLocationField = true;
    // Change folder
    return folderPanel.tryChangeCurrentFolder(location) == null;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) Bookmark(com.mucommander.bookmark.Bookmark) Matcher(java.util.regex.Matcher)

Aggregations

Bookmark (com.mucommander.bookmark.Bookmark)10 AbstractFile (com.mucommander.commons.file.AbstractFile)2 BonjourMenu (com.mucommander.bonjour.BonjourMenu)1 BonjourService (com.mucommander.bonjour.BonjourService)1 FileURL (com.mucommander.commons.file.FileURL)1 MnemonicHelper (com.mucommander.commons.util.ui.helper.MnemonicHelper)1 ProtocolPanelProvider (com.mucommander.protocol.ui.ProtocolPanelProvider)1 MuAction (com.mucommander.ui.action.MuAction)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1