~ubuntu-branches/ubuntu/saucy/filezilla/saucy-proposed

« back to all changes in this revision

Viewing changes to src/interface/RemoteListView.cpp

  • Committer: Package Import Robot
  • Author(s): Adrien Cunin
  • Date: 2012-12-07 17:17:17 UTC
  • mfrom: (1.1.31)
  • Revision ID: package-import@ubuntu.com-20121207171717-nt6as62u4pa1uv11
Tags: 3.6.0.2-1ubuntu1
* Merge from Debian experimental. Remaining Ubuntu change:
   - Added debian/patches/11_use-decimal-si-by-default.patch in order to
     comply with UnitsPolicy

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#define new DEBUG_NEW
29
29
#endif
30
30
 
31
 
class CRemoteListViewDropTarget : public wxDropTarget
 
31
class CRemoteListViewDropTarget : public CListCtrlDropTarget
32
32
{
33
33
public:
34
34
        CRemoteListViewDropTarget(CRemoteListView* pRemoteListView)
35
 
                : m_pRemoteListView(pRemoteListView),
 
35
                : CListCtrlDropTarget(pRemoteListView)
 
36
                , m_pRemoteListView(pRemoteListView),
36
37
                  m_pFileDataObject(new wxFileDataObject()),
37
38
                  m_pRemoteDataObject(new CRemoteDataObject()),
38
39
                  m_pDataObject(new wxDataObjectComposite())
142
143
                }
143
144
 
144
145
                const std::list<CRemoteDataObject::t_fileInfo>& files = m_pRemoteDataObject->GetFiles();
145
 
                for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); iter++)
 
146
                for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
146
147
                {
147
148
                        const CRemoteDataObject::t_fileInfo& info = *iter;
148
149
                        if (info.dir)
157
158
                        }
158
159
                }
159
160
 
160
 
                for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); iter++)
 
161
                for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
161
162
                {
162
163
                        const CRemoteDataObject::t_fileInfo& info = *iter;
163
164
                        m_pRemoteListView->m_pState->m_pCommandQueue->ProcessCommand(
175
176
 
176
177
        virtual bool OnDrop(wxCoord x, wxCoord y)
177
178
        {
 
179
                CListCtrlDropTarget::OnDrop(x, y);
178
180
                ClearDropHighlight();
179
181
 
180
182
                if (!m_pRemoteListView->m_pDirectoryListing)
183
185
                return true;
184
186
        }
185
187
 
186
 
        int DisplayDropHighlight(wxPoint point)
 
188
        virtual void DisplayDropHighlight(wxPoint point)
 
189
        {
 
190
                DoDisplayDropHighlight(point);
 
191
        }
 
192
 
 
193
        int DoDisplayDropHighlight(wxPoint point)
187
194
        {
188
195
                int flags;
189
196
                int hit = m_pRemoteListView->HitTest(point, flags, 0);
228
235
 
229
236
        virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def)
230
237
        {
 
238
                CListCtrlDropTarget::OnDragOver(x, y, def);
 
239
 
231
240
                if (def == wxDragError ||
232
241
                        def == wxDragNone ||
233
242
                        def == wxDragCancel)
245
254
                const CServer* const pServer = m_pRemoteListView->m_pState->GetServer();
246
255
                wxASSERT(pServer);
247
256
 
248
 
                int hit = DisplayDropHighlight(wxPoint(x, y));
 
257
                int hit = DoDisplayDropHighlight(wxPoint(x, y));
249
258
                const CDragDropManager* pDragDropManager = CDragDropManager::Get();
250
259
 
251
260
                if (hit == -1 && pDragDropManager &&
258
267
 
259
268
        virtual void OnLeave()
260
269
        {
 
270
                CListCtrlDropTarget::OnLeave();
261
271
                ClearDropHighlight();
262
272
        }
263
273
 
264
274
        virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def)
265
275
        {
 
276
                CListCtrlDropTarget::OnEnter(x, y, def);
266
277
                return OnDragOver(x, y, def);
267
278
        }
268
279
 
327
338
        EVT_MENU(XRCID("ID_DOWNLOAD"), CRemoteListView::OnMenuDownload)
328
339
        EVT_MENU(XRCID("ID_ADDTOQUEUE"), CRemoteListView::OnMenuDownload)
329
340
        EVT_MENU(XRCID("ID_MKDIR"), CRemoteListView::OnMenuMkdir)
 
341
        EVT_MENU(XRCID("ID_NEW_FILE"), CRemoteListView::OnMenuNewfile)
330
342
        EVT_MENU(XRCID("ID_DELETE"), CRemoteListView::OnMenuDelete)
331
343
        EVT_MENU(XRCID("ID_RENAME"), CRemoteListView::OnMenuRename)
332
344
        EVT_MENU(XRCID("ID_CHMOD"), CRemoteListView::OnMenuChmod)
474
486
                // Find correct position in index mapping
475
487
                std::vector<unsigned int>::iterator start = m_indexMapping.begin();
476
488
                if (m_hasParent)
477
 
                        start++;
 
489
                        ++start;
478
490
                CFileListCtrl<CGenericFileData>::CSortComparisonObject compare = GetSortComparisonObject();
479
491
                std::vector<unsigned int>::iterator insertPos = std::lower_bound(start, m_indexMapping.end(), i, compare);
480
492
                compare.Destroy();
482
494
                const int item = insertPos - m_indexMapping.begin();
483
495
                m_indexMapping.insert(insertPos, i);
484
496
 
485
 
                for (std::list<unsigned int>::iterator iter = added.begin(); iter != added.end(); iter++)
 
497
                for (std::list<unsigned int>::iterator iter = added.begin(); iter != added.end(); ++iter)
486
498
                {
487
499
                        unsigned int &pos = *iter;
488
500
                        if (pos >= (unsigned int)item)
572
584
 
573
585
                // j is the offset the index has to be adjusted
574
586
                int j = 0;
575
 
                for (std::list<unsigned int>::const_iterator iter = removedItems.begin(); iter != removedItems.end(); iter++, j++)
 
587
                for (std::list<unsigned int>::const_iterator iter = removedItems.begin(); iter != removedItems.end(); ++iter, ++j)
576
588
                {
577
589
                        if (*iter > index)
578
590
                                break;
588
600
 
589
601
                // Get old selection
590
602
                bool isSelected = GetItemState(i, wxLIST_STATE_SELECTED) != 0;
591
 
                
 
603
 
592
604
                // Update statusbar info
593
605
                if (removed && m_pFilelistStatusBar)
594
606
                {
634
646
        }
635
647
 
636
648
        // Erase file data
637
 
        for (std::list<unsigned int>::reverse_iterator iter = removedItems.rbegin(); iter != removedItems.rend(); iter++)
 
649
        for (std::list<unsigned int>::reverse_iterator iter = removedItems.rbegin(); iter != removedItems.rend(); ++iter)
638
650
        {
639
651
                m_fileData.erase(m_fileData.begin() + *iter);
640
652
        }
642
654
        // Erase indexes
643
655
        wxASSERT(!toRemove);
644
656
        wxASSERT(removedIndexes.size() == removed);
645
 
        for (std::list<int>::iterator iter = removedIndexes.begin(); iter != removedIndexes.end(); iter++)
 
657
        for (std::list<int>::iterator iter = removedIndexes.begin(); iter != removedIndexes.end(); ++iter)
646
658
        {
647
659
                m_indexMapping.erase(m_indexMapping.begin() + *iter);
648
660
        }
684
696
                wxASSERT(pDirectoryListing->GetCount() == m_pDirectoryListing->GetCount());
685
697
                if (pDirectoryListing->GetCount() != m_pDirectoryListing->GetCount())
686
698
                        return false;
687
 
                
 
699
 
688
700
                m_pDirectoryListing = pDirectoryListing;
689
701
 
690
702
                // We don't have to do anything
756
768
        if (m_pFilelistStatusBar)
757
769
        {
758
770
                m_pFilelistStatusBar->UnselectAll();
759
 
                m_pFilelistStatusBar->SetConnected(pDirectoryListing); 
 
771
                m_pFilelistStatusBar->SetConnected(pDirectoryListing);
760
772
        }
761
773
 
762
774
        m_pDirectoryListing = pDirectoryListing;
1193
1205
        bool back = false;
1194
1206
 
1195
1207
        int item = -1;
1196
 
        while (true)
 
1208
        for (;;)
1197
1209
        {
1198
1210
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1199
1211
                if (item == -1)
1404
1416
                pMenu->Enable(XRCID("ID_EDIT"), false);
1405
1417
                pMenu->Enable(XRCID("ID_GETURL"), false);
1406
1418
                pMenu->Enable(XRCID("ID_CONTEXT_REFRESH"), false);
 
1419
                pMenu->Enable(XRCID("ID_NEW_FILE"), false);
1407
1420
        }
1408
1421
        else if ((GetItemCount() && GetItemState(0, wxLIST_STATE_SELECTED)))
1409
1422
        {
1495
1508
        }
1496
1509
 
1497
1510
        long item = -1;
1498
 
        while (true)
 
1511
        for (;;)
1499
1512
        {
1500
1513
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1501
1514
                if (item == -1)
1541
1554
        bool added = false;
1542
1555
        bool startRecursive = false;
1543
1556
        long item = -1;
1544
 
        while (true)
 
1557
        for (;;)
1545
1558
        {
1546
1559
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1547
1560
                if (item == -1)
1656
1669
        bool selected_link = false;
1657
1670
 
1658
1671
        long item = -1;
1659
 
        while (true)
 
1672
        for (;;)
1660
1673
        {
1661
1674
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1662
1675
                if (item == -1)
1687
1700
 
1688
1701
        wxString question;
1689
1702
        if (!count_dirs)
1690
 
                question.Printf(wxPLURAL("Really delete %d file?", "Really delete %d files?", count_files), count_files);
 
1703
                question.Printf(wxPLURAL("Really delete %d file from the server?", "Really delete %d files from the server?", count_files), count_files);
1691
1704
        else if (!count_files)
1692
 
                question.Printf(wxPLURAL("Really delete %d directory with its contents?", "Really delete %d directories with their contents?", count_dirs), count_dirs);
 
1705
                question.Printf(wxPLURAL("Really delete %d directory with its contents from the server?", "Really delete %d directories with their contents from the server?", count_dirs), count_dirs);
1693
1706
        else
1694
1707
        {
1695
1708
                wxString files = wxString::Format(wxPLURAL("%d file", "%d files", count_files), count_files);
1696
1709
                wxString dirs = wxString::Format(wxPLURAL("%d directory with its contents", "%d directories with their contents", count_dirs), count_dirs);
1697
 
                question.Printf(_("Really delete %s and %s?"), files.c_str(), dirs.c_str());
 
1710
                question.Printf(_("Really delete %s and %s from the server?"), files.c_str(), dirs.c_str());
1698
1711
        }
1699
1712
 
1700
1713
        if (wxMessageBox(question, _("Confirmation needed"), wxICON_QUESTION | wxYES_NO, this) != wxYES)
1722
1735
 
1723
1736
        bool startRecursive = false;
1724
1737
        item = -1;
1725
 
        while (true)
 
1738
        for (;;)
1726
1739
        {
1727
1740
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1728
1741
                if (item == -1)
1933
1946
        char permissions[9] = {0};
1934
1947
 
1935
1948
        long item = -1;
1936
 
        while (true)
 
1949
        for (;;)
1937
1950
        {
1938
1951
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
1939
1952
                if (item == -1)
2008
2021
        wxASSERT(pRecursiveOperation);
2009
2022
 
2010
2023
        item = -1;
2011
 
        while (true)
 
2024
        for (;;)
2012
2025
        {
2013
2026
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2014
2027
                if (item == -1)
2235
2248
        // Reselect previous items if neccessary.
2236
2249
        // Sorting direction did not change. We just have to scan through items once
2237
2250
        unsigned int i = 0;
2238
 
        for (std::list<wxString>::const_iterator iter = selectedNames.begin(); iter != selectedNames.end(); iter++)
 
2251
        for (std::list<wxString>::const_iterator iter = selectedNames.begin(); iter != selectedNames.end(); ++iter)
2239
2252
        {
2240
2253
                while (++i < m_indexMapping.size())
2241
2254
                {
2254
2267
                                        firstSelected = i;
2255
2268
                                if (m_pFilelistStatusBar)
2256
2269
                                        m_pFilelistStatusBar->SelectDirectory();
2257
 
                SetSelection(i, true);
 
2270
                                SetSelection(i, true);
2258
2271
                                break;
2259
2272
                        }
2260
2273
                        else if (*iter == (_T("-") + entry.name))
2392
2405
 
2393
2406
        long item = -1;
2394
2407
        int count = 0;
2395
 
        while (true)
 
2408
        for (;;)
2396
2409
        {
2397
2410
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2398
2411
                if (item == -1)
2439
2452
 
2440
2453
        // Add files to remote data object
2441
2454
        item = -1;
2442
 
        while (true)
 
2455
        for (;;)
2443
2456
        {
2444
2457
                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2445
2458
                if (item == -1)
2511
2524
                        bool idle = m_pState->m_pCommandQueue->Idle();
2512
2525
 
2513
2526
                        long item = -1;
2514
 
                        while (true)
 
2527
                        for (;;)
2515
2528
                        {
2516
2529
                                item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2517
2530
                                if (item == -1)
2570
2583
        }
2571
2584
 
2572
2585
        long item = -1;
2573
 
        
 
2586
 
2574
2587
        std::list<CDirentry> selected_item_list;
2575
2588
        while ((item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1)
2576
2589
        {
2629
2642
                        return;
2630
2643
        }
2631
2644
 
2632
 
        for (std::list<CDirentry>::const_iterator iter = selected_item_list.begin(); iter != selected_item_list.end(); iter++)
 
2645
        for (std::list<CDirentry>::const_iterator iter = selected_item_list.begin(); iter != selected_item_list.end(); ++iter)
2633
2646
        {
2634
2647
                const CDirentry& entry = *iter;
2635
2648
 
3075
3088
        else
3076
3089
        {
3077
3090
                wxString urls;
3078
 
                for (std::list<CDirentry>::const_iterator iter = selected_item_list.begin(); iter != selected_item_list.end(); iter++)
 
3091
                for (std::list<CDirentry>::const_iterator iter = selected_item_list.begin(); iter != selected_item_list.end(); ++iter)
3079
3092
                {
3080
3093
                        urls += server;
3081
3094
                        urls += path.FormatFilename(iter->name, false);
3137
3150
                m_pState->ChangeRemoteDir(m_pDirectoryListing->path, _T(".."));
3138
3151
        }
3139
3152
}
 
3153
 
 
3154
void CRemoteListView::OnMenuNewfile(wxCommandEvent& event)
 
3155
{
 
3156
        if (!m_pState->IsRemoteIdle())
 
3157
        {
 
3158
                wxBell();
 
3159
                return;
 
3160
        }
 
3161
 
 
3162
        CInputDialog dlg;
 
3163
        if (!dlg.Create(this, _("Create empty file"), _("Please enter the name of the file which should be created:")))
 
3164
                return;
 
3165
        
 
3166
        if (dlg.ShowModal() != wxID_OK)
 
3167
                return;
 
3168
        
 
3169
        if (dlg.GetValue() == _T(""))
 
3170
        {
 
3171
                wxBell();
 
3172
                return;
 
3173
        }
 
3174
        
 
3175
        wxString newFileName = dlg.GetValue();
 
3176
        
 
3177
        // Copied from elsewhere in the source, checks for characters that Windows deems invalid
 
3178
        if ((newFileName.Find('/')  != -1) ||
 
3179
                (newFileName.Find('\\') != -1) ||
 
3180
                (newFileName.Find(':')  != -1) ||
 
3181
                (newFileName.Find('*')  != -1) ||
 
3182
                (newFileName.Find('?')  != -1) ||
 
3183
                (newFileName.Find('"')  != -1) ||
 
3184
                (newFileName.Find('<')  != -1) ||
 
3185
                (newFileName.Find('>')  != -1) ||
 
3186
                (newFileName.Find('|')  != -1))
 
3187
        {
 
3188
                wxMessageBox(_("Filename may not contain any of the following characters: / \\ : * ? \" < > |"), _("Invalid filename"), wxICON_EXCLAMATION);
 
3189
                return;
 
3190
        }
 
3191
 
 
3192
        // Check if target file already exists
 
3193
        for (unsigned int i = 0; i < m_pDirectoryListing->GetCount(); i++)
 
3194
        {
 
3195
                if (newFileName == (*m_pDirectoryListing)[i].name)
 
3196
                {
 
3197
                        wxMessageBox(_("Target filename already exists!"));
 
3198
                        return;
 
3199
                }
 
3200
        }
 
3201
        
 
3202
        CEditHandler* edithandler = CEditHandler::Get(); // Used to get the temporary folder
 
3203
        
 
3204
        wxString emptyfile_name = _T("empty_file_yq744zm");
 
3205
        wxString emptyfile = edithandler->GetLocalDirectory() + emptyfile_name;
 
3206
        
 
3207
        // Create the empty temporary file
 
3208
        {
 
3209
                wxFile file;
 
3210
                wxLogNull log;
 
3211
                file.Create(emptyfile);
 
3212
        }
 
3213
        
 
3214
        const CServer* pServer = m_pState->GetServer();
 
3215
        if (!pServer)
 
3216
        {
 
3217
                wxBell();
 
3218
                return;
 
3219
        }
 
3220
        
 
3221
        CFileTransferCommand *cmd = new CFileTransferCommand(emptyfile, m_pDirectoryListing->path, newFileName, false, CFileTransferCommand::t_transferSettings());
 
3222
        m_pState->m_pCommandQueue->ProcessCommand(cmd);
 
3223
}