summaryrefslogtreecommitdiff
path: root/ui/dir_name.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:29:28 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:29:28 +0200
commit75c07011b7c4d06acd7b45dabdcd60ab9d80f385 (patch)
tree8853c3978dd152ef377e652239448b1352320206 /ui/dir_name.cpp
parent5.22 (diff)
downloadFreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.tar.gz
FreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.tar.bz2
FreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.zip
5.23
Diffstat (limited to 'ui/dir_name.cpp')
-rw-r--r--ui/dir_name.cpp274
1 files changed, 0 insertions, 274 deletions
diff --git a/ui/dir_name.cpp b/ui/dir_name.cpp
deleted file mode 100644
index 022773e4..00000000
--- a/ui/dir_name.cpp
+++ /dev/null
@@ -1,274 +0,0 @@
-// **************************************************************************
-// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
-// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
-// **************************************************************************
-
-#include "dir_name.h"
-#include <zen/thread.h>
-#include <zen/file_handling.h>
-#include <wx/dnd.h>
-#include <wx/window.h>
-#include <wx/textctrl.h>
-#include <wx/statbox.h>
-#include <wx/dirdlg.h>
-#include <wx/scrolwin.h>
-#include <wx+/string_conv.h>
-#include <wx+/popup_dlg.h>
-#include "../lib/resolve_path.h"
-#include "folder_history_box.h"
-
-#ifdef ZEN_WIN
-#include <zen/dll.h>
-#include <zen/win_ver.h>
-#include "IFileDialog_Vista\ifile_dialog.h"
-#endif
-
-using namespace zen;
-
-
-const wxEventType zen::EVENT_ON_DIR_SELECTED = wxNewEventType();
-const wxEventType zen::EVENT_ON_DIR_MANUAL_CORRECTION = wxNewEventType();
-
-namespace
-{
-void setDirectoryNameImpl(const wxString& dirname, wxWindow& tooltipWnd, wxStaticText* staticText)
-{
- const wxString dirFormatted = utfCvrtTo<wxString>(getFormattedDirectoryName(toZ(dirname))); //may block when resolving [<volume name>]
-
- tooltipWnd.SetToolTip(nullptr); //workaround wxComboBox bug http://trac.wxwidgets.org/ticket/10512 / http://trac.wxwidgets.org/ticket/12659
- tooltipWnd.SetToolTip(dirFormatted); //who knows when the real bugfix reaches mere mortals via an official release...
-
- if (staticText)
- {
- //change static box label only if there is a real difference to what is shown in wxTextCtrl anyway
- wxString dirNormalized = dirname;
- trim(dirNormalized);
- if (!dirNormalized.empty())
- if (!endsWith(dirNormalized, FILE_NAME_SEPARATOR))
- dirNormalized += FILE_NAME_SEPARATOR;
-
- staticText->SetLabel(dirNormalized == dirFormatted ? wxString(_("Drag && drop")) : dirFormatted);
- }
-}
-
-
-void setDirectoryName(const wxString& dirname,
- wxTextCtrl* txtCtrl,
- wxWindow& tooltipWnd,
- wxStaticText* staticText) //pointers are optional
-{
- if (txtCtrl)
- txtCtrl->ChangeValue(dirname);
- setDirectoryNameImpl(dirname, tooltipWnd, staticText);
-}
-
-
-void setDirectoryName(const wxString& dirname,
- FolderHistoryBox* comboBox,
- wxWindow& tooltipWnd,
- wxStaticText* staticText) //pointers are optional
-{
- if (comboBox)
- comboBox->setValue(dirname);
- setDirectoryNameImpl(dirname, tooltipWnd, staticText);
-}
-}
-//##############################################################################################################
-
-template <class NameControl>
-DirectoryName<NameControl>::DirectoryName(wxWindow& dropWindow,
- wxButton& selectButton,
- NameControl& dirName,
- wxStaticText* staticText,
- wxWindow* dropWindow2) :
- dropWindow_(dropWindow),
- dropWindow2_(dropWindow2),
- selectButton_(selectButton),
- dirName_(dirName),
- staticText_(staticText)
-{
- //prepare drag & drop
- setupFileDrop(dropWindow_);
- dropWindow_.Connect(EVENT_DROP_FILE, FileDropEventHandler(DirectoryName::onFilesDropped), nullptr, this);
-
- if (dropWindow2_)
- {
- setupFileDrop(*dropWindow2_);
- dropWindow2_->Connect(EVENT_DROP_FILE, FileDropEventHandler(DirectoryName::onFilesDropped), nullptr, this);
- }
-
- //keep dirPicker and dirName synchronous
- dirName_ .Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler (DirectoryName::onMouseWheel), nullptr, this);
- dirName_ .Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(DirectoryName::onWriteDirManually), nullptr, this);
- selectButton_.Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DirectoryName::onSelectDir ), nullptr, this);
-}
-
-
-template <class NameControl>
-DirectoryName<NameControl>::~DirectoryName()
-{
- dropWindow_.Disconnect(EVENT_DROP_FILE, FileDropEventHandler(DirectoryName::onFilesDropped), nullptr, this);
- if (dropWindow2_)
- dropWindow2_->Disconnect(EVENT_DROP_FILE, FileDropEventHandler(DirectoryName::onFilesDropped), nullptr, this);
-
- dirName_ .Disconnect(wxEVT_MOUSEWHEEL, wxMouseEventHandler (DirectoryName::onMouseWheel), nullptr, this);
- dirName_ .Disconnect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(DirectoryName::onWriteDirManually), nullptr, this);
- selectButton_.Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(DirectoryName::onSelectDir ), nullptr, this);
-}
-
-
-template <class NameControl>
-void DirectoryName<NameControl>::onMouseWheel(wxMouseEvent& event)
-{
- //for combobox: although switching through available items is wxWidgets default, this is NOT windows default, e.g. explorer
- //additionally this will delete manual entries, although all the users wanted is scroll the parent window!
-
- //redirect to parent scrolled window!
- wxWindow* wnd = &dirName_;
- while ((wnd = wnd->GetParent()) != nullptr) //silence MSVC warning
- if (dynamic_cast<wxScrolledWindow*>(wnd) != nullptr)
- if (wxEvtHandler* evtHandler = wnd->GetEventHandler())
- {
- evtHandler->AddPendingEvent(event);
- break;
- }
-
- // event.Skip();
-}
-
-
-template <class NameControl>
-void DirectoryName<NameControl>::onFilesDropped(FileDropEvent& event)
-{
- const auto& files = event.getFiles();
- if (files.empty())
- return;
-
- if (acceptDrop(files, event.getDropPosition(), event.getDropWindow()))
- {
- const wxString fileName = event.getFiles()[0];
- if (dirExists(toZ(fileName)))
- setDirectoryName(fileName, &dirName_, dirName_, staticText_);
- else
- {
- wxString parentName = beforeLast(fileName, utfCvrtTo<wxString>(FILE_NAME_SEPARATOR)); //returns empty string if ch not found
-#ifdef ZEN_WIN
- if (endsWith(parentName, L":")) //volume name
- parentName += FILE_NAME_SEPARATOR;
-#endif
- if (dirExists(toZ(parentName)))
- setDirectoryName(parentName, &dirName_, dirName_, staticText_);
- else //set original name unconditionally: usecase: inactive mapped network shares
- setDirectoryName(fileName, &dirName_, dirName_, staticText_);
- }
-
- //notify action invoked by user
- wxCommandEvent dummy(EVENT_ON_DIR_SELECTED);
- ProcessEvent(dummy);
- }
- else
- event.Skip(); //let other handlers try!!!
-}
-
-
-template <class NameControl>
-void DirectoryName<NameControl>::onWriteDirManually(wxCommandEvent& event)
-{
- setDirectoryName(event.GetString(), static_cast<NameControl*>(nullptr), dirName_, staticText_);
-
- wxCommandEvent dummy(EVENT_ON_DIR_MANUAL_CORRECTION);
- ProcessEvent(dummy);
- event.Skip();
-}
-
-
-template <class NameControl>
-void DirectoryName<NameControl>::onSelectDir(wxCommandEvent& event)
-{
- wxString defaultDirname; //default selection for dir picker
- {
- const Zstring dirFmt = getFormattedDirectoryName(toZ(getName()));
- if (!dirFmt.empty())
- {
- //convert to Zstring first: we don't want to pass wxString by value and risk MT issues!
- auto ft = async([=] { return zen::dirExists(dirFmt); });
-
- if (ft.timed_wait(boost::posix_time::milliseconds(200)) && ft.get()) //potentially slow network access: wait 200ms at most
- defaultDirname = utfCvrtTo<wxString>(dirFmt);
- }
- }
-
- //wxDirDialog internally uses lame-looking SHBrowseForFolder(); we better use IFileDialog() instead! (remembers size and position!)
- std::unique_ptr<wxString> newFolder;
-#ifdef ZEN_WIN
- if (vistaOrLater())
- {
- using namespace ifile;
- const DllFun<FunType_showFolderPicker> showFolderPicker(getDllName(), funName_showFolderPicker);
- const DllFun<FunType_freeString> freeString (getDllName(), funName_freeString);
- if (showFolderPicker && freeString)
- {
- wchar_t* selectedFolder = nullptr;
- wchar_t* errorMsg = nullptr;
- bool cancelled = false;
- ZEN_ON_SCOPE_EXIT(freeString(selectedFolder));
- ZEN_ON_SCOPE_EXIT(freeString(errorMsg));
-
- const GuidProxy guid = { '\x0', '\x4a', '\xf9', '\x31', '\xb4', '\x92', '\x40', '\xa0',
- '\x8d', '\xc2', '\xc', '\xa5', '\xef', '\x59', '\x6e', '\x3b'
- }; //some random GUID => have Windows save IFileDialog state separately from other file/dir pickers!
-
- showFolderPicker(static_cast<HWND>(selectButton_.GetHWND()), //in; ==HWND
- defaultDirname.empty() ? static_cast<const wchar_t*>(nullptr) : defaultDirname.c_str(), //in, optional!
- &guid,
- selectedFolder, //out: call freeString() after use!
- cancelled, //out
- errorMsg); //out, optional: call freeString() after use!
- if (errorMsg)
- {
- showNotificationDialog(&dropWindow_, DialogInfoType::ERROR2, PopupDialogCfg().setDetailInstructions(errorMsg));
- return;
- }
- if (cancelled || !selectedFolder)
- return;
- newFolder = make_unique<wxString>(selectedFolder);
- }
- }
-#endif
- if (!newFolder.get())
- {
- wxDirDialog dirPicker(&selectButton_, _("Select a folder"), defaultDirname); //put modal wxWidgets dialogs on stack: creating on freestore leads to memleak!
- if (dirPicker.ShowModal() != wxID_OK)
- return;
- newFolder = make_unique<wxString>(dirPicker.GetPath());
- }
-
- setDirectoryName(*newFolder, &dirName_, dirName_, staticText_);
-
- //notify action invoked by user
- wxCommandEvent dummy(EVENT_ON_DIR_SELECTED);
- ProcessEvent(dummy);
-}
-
-
-template <class NameControl>
-wxString DirectoryName<NameControl>::getName() const
-{
- return dirName_.GetValue();
-}
-
-
-template <class NameControl>
-void DirectoryName<NameControl>::setName(const wxString& dirname)
-{
- setDirectoryName(dirname, &dirName_, dirName_, staticText_);
-}
-
-
-//explicit template instantiations
-namespace zen
-{
-template class DirectoryName<wxTextCtrl>;
-template class DirectoryName<FolderHistoryBox>;
-}
bgstack15