File: Dup.h

package info (click to toggle)
4pane 5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,252 kB
  • sloc: cpp: 37,352; sh: 4,109; ansic: 3,620; makefile: 157; xml: 27
file content (122 lines) | stat: -rw-r--r-- 5,022 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/////////////////////////////////////////////////////////////////////////////
// Name:       Dup.h
// Purpose:    Checks/manages Duplication & Renaming
// Part of:    4Pane
// Author:     David Hart
// Copyright:  (c) 2016 David Hart
// Licence:    GPL v3
/////////////////////////////////////////////////////////////////////////////
#ifndef DUPH
#define DUPH
#include "wx/wx.h"
#include <wx/spinctrl.h>

class PasteThreadSuperBlock;

class CheckDupRen
{
public:
CheckDupRen(MyGenericDirCtrl* caller, const wxString& origin_path, const wxString& dest_path, bool fromarchive=false, time_t modtime = 0)  
                                : parent(caller), incomingpath(origin_path), destpath(dest_path), FromArchive(fromarchive), FromModTime(modtime)
      { IsMultiple = false; WhattodoifCantRead = WhattodoifClash = DR_Unknown; m_tsb = NULL; }
bool CheckForAccess(bool recurse = true);   // This is a convenient place to check for read permission when in a Moving/Pasting loop.  Recurse means check permissions of dir contents too --- not needed for Rename
bool CheckForIncest();                      // Ensure we don't try to move a dir onto a descendant --- which would cause an indef loop
enum CDR_Result CheckForPreExistence();     // Ensure we don't accidentally overwrite
int CheckForPreExistenceInArchive();        // Should we overwrite or dup inside an archive
static int RenameFile(wxString& originpath, wxString& originname, wxString& newname, bool dup);  // The ultimate mechanisms.  Static as used by UnRedo too
static int RenameDir(wxString& destpath, wxString& newpath, bool dup);
static bool MultipleRename(wxWindow* parent, wxArrayString& OldFilepaths, wxArrayString& NewFilepaths, bool dup);
static bool ChangeLinkTarget(wxString& linkfilepath, wxString& destfilepath);    // Here for convenience:  change the target of a symlink
void SetTSB(PasteThreadSuperBlock* tsb) { m_tsb = tsb; }
wxString finalpath;
wxString finalbit;
bool ItsADir;
bool IsMultiple;
enum DupRen WhattodoifClash;
enum DupRen WhattodoifCantRead;  // We only use SkipAll this time
wxString GetOverwrittenFilepath() const { return m_overwrittenfilepath; }

protected:
MyGenericDirCtrl* parent;
wxString incomingpath;
wxString inname;
wxString destpath;
wxString destname;
wxString newname;               // The name to call the duplicated/renamed dir/file
wxString stubpath;              // The original destpath splits into stubpath & lastseg
wxString lastseg;

wxString m_overwrittenfilepath;

wxArrayInt IDs;

bool IsDir;
bool dup;                       // Flags whether we're duplicating (intentionally or otherwise)

bool FromArchive;               // Used to flag that we're Pasting from an archive, so can't conveniently rename if there's a clash
time_t FromModTime;             // It's easier to pass the modtime of an archive entry than to work it out here!
PasteThreadSuperBlock* m_tsb;   // Used to coordinate a trashdir

CDR_Result DirAdjustForPreExistence(bool intoArchive = false, time_t modtime = 0);
CDR_Result FileAdjustForPreExistence(bool intoArchive = false, time_t modtime = 0);
enum DupRen OfferToRename(int dialogversion, bool intoArchive = false, time_t modtime = 0);
bool GetNewName(wxString& destpath, wxString& destname);

static bool DoDup(wxString& originalpath, wxString& newpath);  // Used by RenameDir to duplicate dirs, so must be static too
};

class MultipleRenameDlg  :  public wxDialog
{
public:
MultipleRenameDlg(){}
void Init();

wxTextCtrl* IncText;
wxRadioBox* DigitLetterRadio;
wxRadioBox* CaseRadio;
wxRadioButton *ReplaceAllRadio, *ReplaceOnlyRadio;
wxSpinCtrl* MatchSpin;
wxComboBox *ReplaceCombo, *WithCombo;
wxComboBox *PrependCombo, *AppendCombo;
int IncWith, Inc;

protected:
void OnRegexCrib(wxCommandEvent& event);
void OnRadioChanged(wxCommandEvent& event);
void OnSpinUp(wxSpinEvent& event);
void OnSpinDown(wxSpinEvent& event);
void SetIncText();
void PanelUpdateUI(wxUpdateUIEvent& event);
void ReplaceAllRadioClicked(wxCommandEvent& event);
void ReplaceOnlyRadioClicked(wxCommandEvent& event);

enum { digit, upper, lower };
private:
DECLARE_DYNAMIC_CLASS(MultipleRenameDlg)
DECLARE_EVENT_TABLE()
};

class MultipleRename    // Class to implement multiple rename/dup
{
public:
MultipleRename(wxWindow* dad, wxArrayString& OldFP, bool duplicate) : parent(dad), OldFilepaths(OldFP), dup(duplicate) {}
wxArrayString DoRename();
static wxString IncText(int type, int start);
protected:
bool DoRegEx(wxString& String, wxString& ReplaceThis, wxString& WithThis, size_t matches );
bool DoPrependAppend(bool body, wxString& Prepend, wxString& Append);
bool DoInc(bool body, int InitialValue, int type, bool AlwaysInc);
bool CheckForClash(wxString Filepath, size_t index);
void LoadHistory();
void SaveHistory();

enum { digit, upper, lower };
wxWindow* parent;
wxArrayString& OldFilepaths; // This must be a reference, otherwise an only-alter-matching-files situation will make caller lose registration
wxArrayString NewFilepaths;
bool dup;
MultipleRenameDlg dlg;
};

#endif
    // DUPH