Logo Search packages:      
Sourcecode: rapidsvn version File versions  Download package

bool DragAndDropAction::Prepare (  )  [virtual]

Prepare action. This method is execute in the main thread. You can use this method for user interaction. Make sure to call Action::Prepare in every class that inherits from Action. Make sure you check the returned value as well.

Return false to cancel action

See also:
ActionWorker
Return values:
true continue
false cancel

Reimplemented from Action.

Definition at line 148 of file drag_n_drop_action.cpp.

References svn::Path::c_str(), svn::Wc::checkWc(), svn::Path::dirpath(), svn::Path::isUrl(), DragAndDropData::m_action, DragAndDropData::m_destination, DragAndDropData::m_files, DragAndDropData::m_logMessage, DragAndDropData::m_recursiveAdd, and Action::Prepare().

{
  if (!Action::Prepare())
  {
    return false;
  }

  wxString src = wxEmptyString;
  if (m->m_files.GetCount() > 1)
    src = _("Multiple Files");
  else if (m->m_files.GetCount() == 1)
    src = m->m_files[0];
  else
    return false; // No files dragged

  // If the ctrl key is down, then assume the user
  //  wants to copy rather than move files
  bool showMoveButton = (::wxGetKeyState(WXK_CONTROL) == false);

  // Check if the file being dragged-and-dropped is already
  // under source control or is being imported into the repository
  svn::Path srcSvnPath(PathUtf8(m->m_files[0]));
  svn::Path destSvnPath(PathUtf8(m->m_destination));

  bool importFiles = false;
  bool incrementRevision = false;

  // ==DragDrop action patterns==
  // Any entry    -> Same folder        : Nothing to be done
  // Any folder   -> Itself             : Unexpected!
  // Repository   -> Same repository    : Copy/Move action (immediate commit)
  // Repository   -> Other repository   : Unexpected!
  // WC folder    -> Repository         : Unexpected!
  // WC file      -> Repository         : Import action (immediate commit)
  // Plain file   -> Repository         : Import action (immediate commit)
  // Repository   -> WC folder          : Unexpected!
  // Any wc entry -> Same working copy  : Copy/Move action (uncommitied)
  // WC folder    -> Other working copy : Unexpected!
  // WC file      -> Other working copy : Add action (called as import but uncommitied)
  // Plain file   -> WC folder          : Add action (called as import but uncommitied)

  wxArrayString::iterator it;
  for (it = m->m_files.begin(); it != m->m_files.end(); it++)
  {
    if (Utf8ToLocal(PathUtf8(*it).dirpath()) ==
        Utf8ToLocal(PathUtf8(m->m_destination).c_str()))
      return false;
    if (*it == m->m_destination)
      return false;
  }

  if (destSvnPath.isUrl())
  {
    //Drop into repository.

    if (srcSvnPath.isUrl())
    {
      if (!IsInSameTree(m->m_files[0], m->m_destination))
        return false;

      importFiles = false;
      incrementRevision = true;
    }
    else
    {
      for (it = m->m_files.begin(); it != m->m_files.end(); it++)
      {
        if (svn::Wc::checkWc(PathUtf8(*it)))
          return false;
      }

      importFiles = true;
      incrementRevision = true;
    }
  }
  else
  {
    //Drop into working copy.

    if (srcSvnPath.isUrl())
      return false;
    else if (svn::Wc::checkWc(srcSvnPath.dirpath()) &&
             IsInSameTree(m->m_files[0], m->m_destination))
    {
      importFiles = false;
      incrementRevision = false;
    }
    else {
      for (it = m->m_files.begin(); it != m->m_files.end(); it++)
      {
        if (svn::Wc::checkWc(PathUtf8(*it)))
          return false;
      }

      importFiles = true;
      incrementRevision = false;
    }
    m->m_recursiveAdd = true;
  }

  // Present the confirmation dialog to the user
  DragAndDropDialog dlg(m_parent, src, m->m_destination,
                        showMoveButton, importFiles);
  m->m_action = dlg.ShowModal();

  if (DragAndDropDialog::RESULT_CANCEL == m->m_action)
    return false;

  // Imports require additional information from the user
  //  so present the commit dialog to get that information
  if (DragAndDropDialog::RESULT_IMPORT == m->m_action && incrementRevision)
  {
    CommitDlg commitDlg(m_parent);
    if (commitDlg.ShowModal() != wxID_OK)
      return false;

    m->m_logMessage = commitDlg.GetMessage();
    m->m_recursiveAdd = commitDlg.GetRecursive();
  }

  return true;
}


Generated by  Doxygen 1.6.0   Back to index