summaryrefslogtreecommitdiff
path: root/ui/MainDialog.h
blob: 6e60fab3f65515106b3e1ff0112e893b05d48b4f (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/***************************************************************
 * Name:      mainDialog.h
 * Purpose:   Defines Application Frame
 * Author:    ZenJu (zhnmju123@gmx.de)
 * Created:   2008-07-16
 **************************************************************/

#ifndef MAINDIALOG_H
#define MAINDIALOG_H

#include "guiGenerated.h"
#include "syncDialog.h"
#include "smallDialogs.h"
#include "../library/resources.h"
#include "../library/misc.h"
#include <wx/dnd.h>
#include <stack>
#include "../library/processXml.h"
#include <wx/event.h>
#include <memory>


//IDs for context menu items
enum //context menu for left and right grids
{
    CONTEXT_FILTER_TEMP = 10,
    CONTEXT_EXCLUDE_EXT,
    CONTEXT_EXCLUDE_OBJ,
    CONTEXT_CLIPBOARD,
    CONTEXT_EXPLORER,
    CONTEXT_DELETE_FILES,
};

enum //context menu for middle grid
{
    CONTEXT_CHECK_ALL,
    CONTEXT_UNCHECK_ALL
};

enum //context menu for column settings
{
    CONTEXT_CUSTOMIZE_COLUMN_LEFT,
    CONTEXT_CUSTOMIZE_COLUMN_RIGHT
};

class CompareStatusHandler;
class FileDropEvent;
class FfsFileDropEvent;

class MainDialog : public MainDialogGenerated
{
    friend class CompareStatusHandler;
    friend class FileDropEvent;

public:
    MainDialog(wxFrame* frame, const wxString& cfgFileName, CustomLocale* language, xmlAccess::XmlGlobalSettings& settings);
    ~MainDialog();

private:
    void cleanUp();

    //configuration load/save
    bool readConfigurationFromXml(const wxString& filename, bool programStartup = false);
    bool writeConfigurationToXml(const wxString& filename);

    void readGlobalSettings();
    void writeGlobalSettings();

    void updateViewFilterButtons();
    void updateFilterButton(wxBitmapButton* filterButton, bool isActive);
    void updateCompareButtons();

    void addFileToCfgHistory(const wxString& filename);
    void addLeftFolderToHistory(const wxString& leftFolder);
    void addRightFolderToHistory(const wxString& rightFolder);

    void addFolderPair(const Zstring& leftDir, const Zstring& rightDir);
    void addFolderPair(const std::vector<FolderPair>& newPairs);
    void removeFolderPair(const int pos, bool refreshLayout = true); //keep it an int, allow negative values!
    void clearFolderPairs();

    //main method for putting gridData on UI: maps data respecting current view settings
    void writeGrid(const FileCompareResult& gridData);
    void mapGridDataToUI(GridView& output, const FileCompareResult& fileCmpResult);
    void updateStatusInformation(const GridView& output);

    //context menu functions
    std::set<int> getSelectedRows(const wxGrid* grid);
    void filterRangeManually(const std::set<int>& rowsToFilterOnUiTable);
    void copySelectionToClipboard(const wxGrid* selectedGrid);
    void openWithFileManager(int rowNumber, const wxGrid* grid);
    void deleteFilesOnGrid(const std::set<int>& selectedRowsLeft, const std::set<int>& selectedRowsRight);

    //work to be done in idle time
    void OnIdleEvent(wxEvent& event);

    //delayed status information restore
    void pushStatusInformation(const wxString& text);
    void clearStatusBar();

    //events
    void onGridLeftButtonEvent(wxKeyEvent& event);
    void onGridRightButtonEvent(wxKeyEvent& event);
    void onGridMiddleButtonEvent(wxKeyEvent& event);
    void OnContextMenu(wxGridEvent& event);
    void OnContextMenuSelection(wxCommandEvent& event);
    void OnContextMenuMiddle(wxGridEvent& event);
    void OnContextMenuMiddleSelection(wxCommandEvent& event);
    void OnContextColumnLeft(wxGridEvent& event);
    void OnContextColumnRight(wxGridEvent& event);
    void OnContextColumnSelection(wxCommandEvent& event);

    void OnWriteDirManually(wxCommandEvent& event);
    void OnDirSelected(wxFileDirPickerEvent& event);

    //manual filtering of rows:
    void OnGridSelectCell(wxGridEvent& event);
    void OnGrid3LeftMouseUp(wxEvent& event);
    void OnGrid3LeftMouseDown(wxEvent& event);

    void OnLeftGridDoubleClick( wxGridEvent& event);
    void OnRightGridDoubleClick(wxGridEvent& event);
    void OnSortLeftGrid(        wxGridEvent& event);
    void OnSortRightGrid(       wxGridEvent& event);
    void OnSortMiddleGrid(      wxGridEvent& event);

    void OnLeftOnlyFiles(       wxCommandEvent& event);
    void OnLeftNewerFiles(      wxCommandEvent& event);
    void OnDifferentFiles(      wxCommandEvent& event);
    void OnRightNewerFiles(     wxCommandEvent& event);
    void OnRightOnlyFiles(      wxCommandEvent& event);
    void OnEqualFiles(          wxCommandEvent& event);

    void OnSaveConfig(          wxCommandEvent& event);
    void OnLoadConfig(          wxCommandEvent& event);
    void OnLoadFromHistory(     wxCommandEvent& event);
    void loadConfiguration(const wxString& filename);
    void OnCfgHistoryKeyEvent(  wxKeyEvent& event);
    void OnFolderHistoryKeyEvent(wxKeyEvent& event);

    void OnFilesDropped(        FfsFileDropEvent& event);
    void onResizeMainWindow(    wxEvent& event);
    void OnAbortCompare(        wxCommandEvent& event);
    void OnFilterButton(        wxCommandEvent& event);
    void OnHideFilteredButton(  wxCommandEvent& event);
    void OnConfigureFilter(     wxHyperlinkEvent& event);
    void OnShowHelpDialog(      wxCommandEvent& event);
    void OnSwapDirs(            wxCommandEvent& event);
    void OnCompareByTimeSize(   wxCommandEvent& event);
    void OnCompareByContent(    wxCommandEvent& event);
    void OnCompare(             wxCommandEvent& event);
    void OnSync(                wxCommandEvent& event);
    void OnClose(               wxCloseEvent&   event);
    void OnQuit(                wxCommandEvent& event);

    void OnAddFolderPair(       wxCommandEvent& event);
    void OnRemoveFolderPair(    wxCommandEvent& event);

    //menu events
    void OnMenuSaveConfig(      wxCommandEvent& event);
    void OnMenuLoadConfig(      wxCommandEvent& event);
    void OnMenuGlobalSettings(  wxCommandEvent& event);
    void OnMenuExportFileList(  wxCommandEvent& event);
    void OnMenuBatchJob(        wxCommandEvent& event);
    void OnMenuCheckVersion(    wxCommandEvent& event);
    void OnMenuAbout(           wxCommandEvent& event);
    void OnMenuQuit(            wxCommandEvent& event);
    void OnMenuLangChineseSimp( wxCommandEvent& event);
    void OnMenuLangDutch(       wxCommandEvent& event);
    void OnMenuLangEnglish(     wxCommandEvent& event);
    void OnMenuLangFrench(      wxCommandEvent& event);
    void OnMenuLangGerman(      wxCommandEvent& event);
    void OnMenuLangHungarian(   wxCommandEvent& event);
    void OnMenuLangItalian(     wxCommandEvent& event);
    void OnMenuLangJapanese(    wxCommandEvent& event);
    void OnMenuLangPolish(      wxCommandEvent& event);
    void OnMenuLangPortuguese(  wxCommandEvent& event);
    void OnMenuLangSlovenian(   wxCommandEvent& event);
    void OnMenuLangSpanish(     wxCommandEvent& event);

    void switchProgramLanguage(const int langID);
    void enableSynchronization(bool value);

//***********************************************
    //application variables are stored here:

    //global settings used by GUI and batch mode
    xmlAccess::XmlGlobalSettings& globalSettings;

    //technical representation of grid-data
    FileCompareResult currentGridData;

    //UI view of currentGridData
    GridView gridRefUI;

//-------------------------------------
    //functional configuration
    MainConfiguration cfg;

    //folder pairs:
    //m_directoryLeft, m_directoryRight
    std::vector<FolderPairGenerated*> additionalFolderPairs; //additional pairs to the standard pair

    //gui settings
    int widthNotMaximized;
    int heightNotMaximized;
    int posXNotMaximized;
    int posYNotMaximized;
    bool hideFilteredElements;
    bool ignoreErrors;
//-------------------------------------

    //convenience method to get all folder pairs (unformatted)
    std::vector<FolderPair> getFolderPairs();

    //UI View Filter settings
    bool leftOnlyFilesActive;
    bool leftNewerFilesActive;
    bool differentFilesActive;
    bool equalFilesActive;
    bool rightNewerFilesActive;
    bool rightOnlyFilesActive;

//***********************************************
    std::auto_ptr<wxMenu> contextMenu;

    CustomLocale* programLanguage;

    //status information
    wxLongLong lastStatusChange;
    std::stack<wxString> stackObjects;

    //compare status panel (hidden on start, shown when comparing)
    CompareStatus* compareStatus;

    //save the last used config filename history
    std::vector<wxString> cfgFileNames;

    //used when saving configuration
    wxString proposedConfigFileName;

    //variables for filtering of m_grid3
    bool filteringInitialized;
    bool filteringPending;

    //temporal variables used by exclude via context menu
    wxString exFilterCandidateExtension;
    struct FilterObject
    {
        wxString relativeName;
        FileDescrLine::ObjectType type;
    };
    std::vector<FilterObject> exFilterCandidateObj;

    bool synchronizationEnabled; //determines whether synchronization should be allowed

    CompareStatusHandler* cmpStatusHandlerTmp;  //used only by the abort button when comparing

    bool cleanedUp; //determines if destructor code was already executed

    //remember last sort executed (for determination of sort order)
    int lastSortColumn;
    const wxGrid* lastSortGrid;
};

//######################################################################################

//define new event type
const wxEventType FFS_DROP_FILE_EVENT = wxNewEventType();
typedef void (wxEvtHandler::*FffsFileDropEventFunction)(FfsFileDropEvent&);
#define FfsFileDropEventHandler(func) \
    (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(FffsFileDropEventFunction, &func)

class FfsFileDropEvent : public wxCommandEvent
{
public:
    FfsFileDropEvent(const wxString& nameDropped, const wxPanel* dropTarget) :
            wxCommandEvent(FFS_DROP_FILE_EVENT),
            m_nameDropped(nameDropped),
            m_dropTarget(dropTarget) {}

    virtual wxEvent* Clone() const
    {
        return new FfsFileDropEvent(m_nameDropped, m_dropTarget);
    }

    const wxString m_nameDropped;
    const wxPanel* m_dropTarget;
};


class MainWindowDropTarget : public wxFileDropTarget
{
public:
    MainWindowDropTarget(MainDialog* dlg, const wxPanel* obj) :
            mainDlg(dlg),
            dropTarget(obj) {}

    virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);

private:
    MainDialog* mainDlg;
    const wxPanel* dropTarget;
};

//######################################################################################

//classes handling sync and compare error as well as status information

class CompareStatusHandler : public StatusHandler
{
public:
    CompareStatusHandler(MainDialog* dlg);
    ~CompareStatusHandler();

    virtual void updateStatusText(const Zstring& text);
    virtual void initNewProcess(int objectsTotal, double dataTotal, Process processID);
    virtual void updateProcessedData(int objectsProcessed, double dataProcessed);
    virtual void forceUiRefresh();

    virtual ErrorHandler::Response reportError(const Zstring& text);
    virtual void reportFatalError(const Zstring& errorMessage);
    virtual void reportWarning(const Zstring& warningMessage, bool& dontShowAgain);

private:
    virtual void abortThisProcess();

    MainDialog* mainDialog;
    bool ignoreErrors;
    Process currentProcess;
};


class SyncStatusHandler : public StatusHandler
{
public:
    SyncStatusHandler(wxWindow* dlg, bool ignoreAllErrors);
    ~SyncStatusHandler();

    virtual void updateStatusText(const Zstring& text);
    virtual void initNewProcess(int objectsTotal, double dataTotal, Process processID);
    virtual void updateProcessedData(int objectsProcessed, double dataProcessed);
    virtual void forceUiRefresh();

    virtual ErrorHandler::Response reportError(const Zstring& text);
    virtual void reportFatalError(const Zstring& errorMessage);
    virtual void reportWarning(const Zstring& warningMessage, bool& dontShowAgain);

private:
    virtual void abortThisProcess();

    SyncStatus* syncStatusFrame;
    bool ignoreErrors;
    wxArrayString unhandledErrors;   //list of non-resolved errors
};


#endif // MAINDIALOG_H
bgstack15