Ticket #1526: getpathellipsis CPP.patch

File getpathellipsis CPP.patch, 1.9 KB (added by xalspaero, 12 years ago)
  • fileexistsdlg.cpp

     
    11#include "FileZilla.h"
    22#include "fileexistsdlg.h"
    33
     4#include <wx/display.h>
     5#include <wx/string.h>
     6
    47BEGIN_EVENT_TABLE(CFileExistsDlg, wxDialogEx)
    58EVT_BUTTON(XRCID("wxID_OK"), CFileExistsDlg::OnOK)
    69EVT_BUTTON(XRCID("wxID_CANCEL"), CFileExistsDlg::OnCancel)
     
    4144
    4245    wxString remoteFile = m_pNotification->remotePath.GetPath() + m_pNotification->remoteFile;
    4346    remoteFile.Replace(_T("&"), _T("&&"));
     47   
     48    localFile = GetPathEllipsis(localFile,FindWindow(XRCID("ID_FILE1_NAME")));
     49    remoteFile = GetPathEllipsis(remoteFile,FindWindow(XRCID("ID_FILE2_NAME")));
    4450
    4551    if (m_pNotification->download)
    4652    {
     
    280286    queueOnly = m_queueOnly;
    281287    return m_always;
    282288}
     289
     290wxString CFileExistsDlg::GetPathEllipsis(wxString path, wxWindow *window)
     291{
     292    int string_width; // width of the path string in pixels
     293    int y;            // dummy variable
     294    window->GetTextExtent(path,&string_width,&y);
     295
     296    wxDisplay display(wxDisplay::GetFromWindow(window));
     297    wxRect rect = display.GetClientArea();
     298    const float DESKTOP_WIDTH = rect.GetWidth(); // width of the desktop in pixels
     299
     300    // if the path is already short enough, don't change it
     301    if ((float)string_width / DESKTOP_WIDTH <= 0.70)
     302        return path;
     303
     304    int middle = path.Length()/2;
     305
     306    // continue removing one character at a time until path string is small enough
     307    while ((float)string_width / DESKTOP_WIDTH > 0.70)
     308    {
     309        path = path.Left(middle-1) + path.Mid(middle+1);
     310        middle = path.Length()/2;
     311        window->GetTextExtent(path,&string_width,&y); // get the new, smaller string_width
     312    }
     313
     314    if(path.length() >= middle+1)
     315    {
     316        path[middle-1] = ' ';
     317        path[middle] = 0x2026; // insert unicode ellipsis character
     318        path[middle+1] = ' ';
     319    }
     320
     321    return path;
     322}