public String getText() {
   if (_text != null) {
     return _text;
   } else if (_playlist != null && _playlist.getName() != null) {
     return _playlist.getName();
   } else {
     return "";
   }
 }
 public AddToPlaylistAction(Playlist playlist) {
   super(getTruncatedString(playlist.getName(), MAX_VISIBLE_PLAYLIST_NAME_LENGTH_IN_MENU));
   putValue(
       Action.LONG_DESCRIPTION,
       I18n.tr("Add to playlist") + " \"" + getValue(Action.NAME) + "\"");
   System.out.println("Truncated playlist name was:" + " " + getValue(Action.NAME));
   this.playlist = playlist;
 }
  /** Saves a playlist. */
  public void exportM3U(Playlist playlist) {

    if (playlist == null) {
      return;
    }

    String suggestedName = CommonUtils.convertFileName(playlist.getName());

    // get the user to select a new one.... avoid FrostWire installation folder.
    File suggested;
    File suggestedDirectory = FileChooserHandler.getLastInputDirectory();
    if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) {
      suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop");
    }

    suggested = new File(suggestedDirectory, suggestedName + ".m3u");

    File selFile =
        FileChooserHandler.getSaveAsFile(
            GUIMediator.getAppFrame(),
            I18nMarker.marktr("Save Playlist As"),
            suggested,
            new PlaylistListFileFilter());

    // didn't select a file?  nothing we can do.
    if (selFile == null) {
      return;
    }

    // if the file already exists and not the one just opened, ask if it should be
    //  overwritten.
    // TODO: this should be handled in the jfilechooser
    if (selFile.exists()) {
      DialogOption choice =
          GUIMediator.showYesNoMessage(
              I18n.tr(
                  "Warning: a file with the name {0} already exists in the folder. Overwrite this file?",
                  selFile.getName()),
              QuestionsHandler.PLAYLIST_OVERWRITE_OK,
              DialogOption.NO);
      if (choice != DialogOption.YES) return;
    }

    String path = selFile.getPath();
    try {
      path = FileUtils.getCanonicalPath(selFile);
    } catch (IOException ignored) {
      // LOG.warn("unable to get canonical path for file: " + selFile, ignored);
    }
    // force m3u on the end.
    if (!path.toLowerCase().endsWith(".m3u")) path += ".m3u";

    // create a new thread to handle saving the playlist to disk
    saveM3U(playlist, path);
  }
 public void actionPerformed(ActionEvent e) {
   Playlist playlist = getSelectedPlaylist();
   if (playlist != null) {
     List<File> files = new ArrayList<File>();
     for (PlaylistItem item : playlist.getItems()) {
       File file = new File(item.getFilePath());
       files.add(file);
     }
     iTunesMediator.instance().addSongsiTunes(playlist.getName(), files.toArray(new File[0]));
   }
 }