26#include "../common/vcsmanager.hpp"
27#include "../common/filerevisions.hpp"
29#define wxUSE_DRAG_AND_DROP 1
31#if wxUSE_DRAG_AND_DROP
45 wxDataObjectComposite* dataobj =
new wxDataObjectComposite();
49 dataobj->Add(
new wxTextDataObject(),
true);
50 dataobj->Add(
new wxFileDataObject());
53 dataobj->Add(
new wxFileDataObject(),
true);
55 SetDataObject(dataobj);
75 defaultDragResult = edit->DoDragOver(x, y, defaultDragResult);
80 wxDataObjectComposite* dataobj =
static_cast<wxDataObjectComposite*
>(GetDataObject());
81 wxDataFormat
format = dataobj->GetReceivedFormat();
84 if (
format.GetType() == wxDF_TEXT ||
format.GetType() == wxDF_UNICODETEXT)
89 wxTreeItemId currentId = tree->HitTest(wxPoint(x,y));
96 return defaultDragResult;
111 wxDataObjectComposite* dataobj =
static_cast<wxDataObjectComposite*
>(GetDataObject());
112 wxDataFormat
format = dataobj->GetReceivedFormat();
113 wxDataObject* data = dataobj->GetObject(
format);
121 wxFileDataObject* filedata =
static_cast<wxFileDataObject*
>(data);
122 wxArrayString filenames = filedata->GetFilenames();
125 std::vector<std::string> vPaths = top->
getPathDefs();
133 for (
size_t i = 0; i < filenames.size(); i++)
135 while (filenames.size()
141 filenames.erase(filenames.begin()+i);
146 if (!filenames.size())
156 std::string sExecutables;
157 std::string sLoadables;
160 for (
size_t i = 0; i < filenames.size(); i++)
162 while (filenames.size()
166 filenames.erase(filenames.begin()+i);
169 if (!filenames.size())
177 if (sExecutables.length())
181 if (filenames[i].find(
".nscr") != std::string::npos)
184 sScriptName.erase(sScriptName.rfind(
".nscr"));
187 sScriptName.erase(0, vPaths[
SCRIPTPATH].length());
189 while (sScriptName.front() ==
'/')
190 sScriptName.erase(0,1);
192 if (sScriptName.find(
' ') != std::string::npos)
193 sScriptName =
"\"" + sScriptName +
"\"";
195 sExecutables +=
"start " + sScriptName;
200 sProcName.erase(sProcName.rfind(
".nprc"));
204 sProcName.erase(0, vPaths[
PROCPATH].length());
206 while (sProcName.front() ==
'/')
207 sProcName.erase(0,1);
209 while (sProcName.find(
'/') != std::string::npos)
210 sProcName[sProcName.find(
'/')] =
'~';
213 sProcName =
"'" + sProcName +
"'";
215 sExecutables +=
"$" + sProcName +
"()";
220 if (sLoadables.length())
230 if (!filenames.size())
234 if (sLoadables.length())
238 if (sExecutables.length())
253 if (dragdropsource.IsOk() && (
static_cast<FileNameTreeData*
>(tree->GetItemData(dragdropsource)))->filename == filenames[0])
255 wxTreeItemId dragdroptarget = tree->HitTest(wxPoint(x,y));
258 if (pathname.length())
260 wxString filename = pathname +
"\\" + filenames[0].substr(filenames[0].rfind(
'\\')+1);
263 if (wxFileName(filename) == wxFileName(filenames[0]))
274 std::unique_ptr<FileRevisions> revisions(manager.
getRevisions(filenames[0]));
278 revisions->moveFile(filenames[0], filename, manager.
getRevisionPath(filename));
284 if (wxCopyFile(filenames[0], filename,
true))
285 wxRemoveFile(filenames[0]);
288 return defaultDragResult;
296 for (
size_t i = 0; i < filenames.size(); i++)
298 while (filenames.size()
301 filenames.erase(filenames.begin()+i);
304 if (!filenames.size())
318 if (wxFileExists(vPaths[
LOADPATH] + sFileName.substr(sFileName.rfind(
'/')))
319 || wxFileExists(vPaths[
SAVEPATH] + sFileName.substr(sFileName.rfind(
'/'))))
322 wxCopyFile(sFileName, vPaths[
LOADPATH] + sFileName.substr(sFileName.rfind(
'/')));
334 if (sFileName.find(
".nscr") != std::string::npos)
339 if (wxFileExists(vPaths[pathID] + sFileName.substr(sFileName.rfind(
'/'))))
342 wxCopyFile(sFileName, vPaths[pathID] + sFileName.substr(sFileName.rfind(
'/')));
353 if (wxFileExists(vPaths[pathID] + sFileName.substr(sFileName.rfind(
'/'))))
356 wxCopyFile(sFileName, vPaths[pathID] + sFileName.substr(sFileName.rfind(
'/')));
367 case wxDF_UNICODETEXT:
374 wxTextDataObject* textdata =
static_cast<wxTextDataObject*
>(data);
376 edit->DoDropText(x, y, textdata->GetText());
383 wxTextDataObject* textdata =
static_cast<wxTextDataObject*
>(data);
384 std::string sText = textdata->GetText().ToStdString();
389 for (
size_t i = 0; i < sText.length(); i++)
391 if (sText[i] ==
'"' && (!i || sText[i-1] !=
'\\'))
397 if (sText.substr(i, 2) ==
"##")
399 size_t p = sText.find(
'\n', i);
402 if (p == std::string::npos)
406 sText.insert(p,
"*#");
415 while ((pos = sText.find(
"\\\\")) != std::string::npos
416 && (pos2 = sText.find_first_not_of(
" \t", pos+2)) != std::string::npos
417 && sText[pos2] ==
'\n')
419 sText.replace(pos, pos2-pos+1,
" ");
424 while ((pos = sText.find(
'\n')) != std::string::npos)
427 && sText.find_last_not_of(
" \t", pos-1) != std::string::npos
428 && sText[sText.find_last_not_of(
" \t", pos-1)] !=
';')
434 while ((pos = sText.find(
'\t')) != std::string::npos)
440 defaultDragResult = wxDragCopy;
447 return defaultDragResult;
459 if (filename.find(
'.') == std::string::npos)
464 static wxString textExtensions =
";txt;dat;log;tex;csv;jdx;jcm;dx;nhlp;nlyt;ndb;nlng;def;ini;hlpidx;m;cpp;hpp;c;h;cxx;hxx;xml;diff;";
465 static wxString binaryExtensions =
";ndat;xls;xlsx;ods;labx;ibw;";
466 static wxString imageExtensions =
";png;gif;jpg;jpeg;bmp;eps;svg;";
467 static wxString execExtensions =
";nscr;nprc;";
469 wxString extension =
";"+filename.substr(filename.rfind(
'.')+1).Lower()+
";";
472 if (textExtensions.find(extension) != std::string::npos)
475 if (binaryExtensions.find(extension) != std::string::npos)
478 if (imageExtensions.find(extension) != std::string::npos)
481 if (execExtensions.find(extension) != std::string::npos)
This class provides the needed functionalities for the file tree and the symbols tree.
void SetDnDHighlight(const wxTreeItemId &itemToHighLight)
NumeReDropTarget(wxWindow *topwindow, wxWindow *owner, parentType type)
Constructor. Initializes the data objects, which correspond to the assigned wxWindow.
wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult defaultDragResult)
This method handles the file operations after DragDrop.
fileType getFileType(const wxString &filename)
This method classifies the file type of the passed file type.
wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult defaultDragResult)
This method visualizes the DragDrop effect.
The class of the editor window.
void pass_command(const std::string &command, bool isEvent)
Pass the external command to the kernel without printing it to the console.
virtual void ProcessInput(int len, const std::string &sData) override
Processes text received from the keybord or clipboard.
This class is the actual NumeRe main frame. The application's logic is implemented here.
std::vector< std::string > getPathDefs()
This member function returns the standard path definitions as a vector.
void OpenSourceFile(wxArrayString fnames, unsigned int nLine=0, int nOpenFileFlag=OPENFILE_NOTHING)
Opens the given list of source files in the editor.
NumeReEditor * GetCurrentEditor()
Public access method for accessing the currently viewed editor. Does only return a pointer to the top...
wxTreeItemId getDragDropSourceItem()
This member function gets the drag-drop source item, if the source was the file tree.
NumeReTerminal * getTerminal()
wxString getTreeFolderPath(const wxTreeItemId &itemId)
This member function returns the paths connected to a specific directory in the file tree.
void UpdateLocationIfOpen(const wxFileName &fname, const wxFileName &newFName)
Updates the editor's and notebook's filename location, if it already opened and not modified.
bool hasRevisions(const wxString ¤tFile)
This method detects, whether the selected file has revisions.
wxString getRevisionPath(const wxString ¤tFilePath)
This method returns the path, where the revisions are stored.
FileRevisions * getRevisions(const wxString ¤tFile)
This method returns the file revisions as pointer.
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > & >(), fmt, tp), std::basic_string< CharT >{})
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.