summaryrefslogtreecommitdiff
path: root/ui/MainDialog.h
blob: e8eae78372f6853e5c2ef821e5cb03591a213dff (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
/***************************************************************
 * Name:      mainDialog.h
 * Purpose:   Main Application Dialog
 * Author:    ZenJu (zhnmju123@gmx.de)
 * Created:   2008-07-16
 **************************************************************/

#ifndef MAINDIALOG_H
#define MAINDIALOG_H

#include "guiGenerated.h"
#include <stack>
#include "../library/processXml.h"
#include "gridView.h"
#include <memory>
#include <map>

class CompareStatusHandler;
class CompareStatus;
class MainFolderDragDrop;
class FolderPairPanel;
class CustomGrid;
class FFSCheckRowsEvent;
class FFSSyncDirectionEvent;
class SyncPreview;
class IconUpdater;

namespace FreeFileSync
{
    class CustomLocale;
}


class MainDialog : public MainDialogGenerated
{
    friend class CompareStatusHandler;
    friend class MainFolderDragDrop;
    friend class SyncPreview;

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

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

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

    enum ContextIDMiddleLabel
    {
        CONTEXT_COMPARISON_RESULT = 30,
        CONTEXT_SYNC_PREVIEW
    };


public:
    MainDialog(wxFrame* frame,
               const wxString& cfgFileName,
               FreeFileSync::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);
    xmlAccess::XmlGuiConfig getCurrentConfiguration() const;

    xmlAccess::XmlGuiConfig lastConfigurationSaved; //support for: "Save changed configuration?" dialog

    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, bool addFront = false);
    void addFolderPair(const std::vector<FreeFileSync::FolderPair>& newPairs, bool addFront = false);
    void removeFolderPair(const int pos, bool refreshLayout = true); //keep it an int, allow negative values!
    void clearFolderPairs();

    //main method for putting gridDataView on UI: updates data respecting current view settings
    void updateGuiGrid();

    void updateGridViewData();

    //context menu functions
    std::set<int> getSelectedRows(const CustomGrid* grid) const;
    std::set<int> getSelectedRows() const;
    void setSyncDirManually(const std::set<int>& rowsToSetOnUiTable, const FreeFileSync::SyncDirection dir);
    void filterRangeManually(const std::set<int>& rowsToFilterOnUiTable, const int leadingRow);
    void copySelectionToClipboard(const CustomGrid* selectedGrid);
    void openWithFileManager(const int rowNumber, const bool leftSide);
    void deleteSelectedFiles();

    //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 OnContextRim(                 wxGridEvent& event);
    void OnContextRimSelection(        wxCommandEvent& event);
    void OnContextRimLabelLeft(        wxGridEvent& event);
    void OnContextRimLabelRight(       wxGridEvent& event);
    void OnContextRimLabelSelection(   wxCommandEvent& event);
    void OnContextMiddle(              wxGridEvent& event);
    void OnContextMiddleSelection(     wxCommandEvent& event);
    void OnContextMiddleLabel(         wxGridEvent& event);
    void OnContextMiddleLabelSelection(wxCommandEvent& event);

    void OnDirSelected(wxFileDirPickerEvent& event);

    void requestShutdown(); //try to exit application

    void OnCheckRows(FFSCheckRowsEvent& event);
    void OnSetSyncDirection(FFSSyncDirectionEvent& event);

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

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

    void OnSyncDirLeft(         wxCommandEvent& event);
    void OnSyncDirRight(        wxCommandEvent& event);
    void OnSyncDirNone(         wxCommandEvent& event);

    void OnSaveConfig(          wxCommandEvent& event);
    void OnLoadConfig(          wxCommandEvent& event);
    void OnLoadFromHistory(     wxCommandEvent& event);
    bool trySaveConfig(); //return true if saved successfully

    void loadConfiguration(const wxString& filename);
    void OnCfgHistoryKeyEvent(  wxKeyEvent& event);
    void OnFolderHistoryKeyEvent(wxKeyEvent& event);
    void OnRegularUpdateCheck(  wxIdleEvent& event);
    void OnLayoutWindowAsync(   wxIdleEvent& event);

    void refreshGridAfterFilterChange(const int delay);

    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 OnSwapSides(           wxCommandEvent& event);
    void OnCompareByTimeSize(   wxCommandEvent& event);
    void OnCompareByContent(    wxCommandEvent& event);
    void OnCompare(             wxCommandEvent& event);
    void OnSwitchView(          wxCommandEvent& event);
    void OnSyncSettings(        wxCommandEvent& event);
    void OnStartSync(           wxCommandEvent& event);
    void OnClose(               wxCloseEvent&   event);
    void OnQuit(                wxCommandEvent& event);

    void calculatePreview();

    void OnAddFolderPair(       wxCommandEvent& event);
    void OnRemoveFolderPair(    wxCommandEvent& event);
    void OnRemoveTopFolderPair( 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 OnMenuLanguageSwitch(  wxCommandEvent& event);

    void switchProgramLanguage(const int langID);

    typedef int MenuItemID;
    typedef int LanguageID;
    std::map<MenuItemID, LanguageID> languageMenuItemMap; //needed to attach menu item events

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

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

    //technical representation of grid-data
    FreeFileSync::FolderComparison currentGridData;

    //UI view of currentGridData
    FreeFileSync::GridView gridDataView;

//-------------------------------------
    //functional configuration
    FreeFileSync::MainConfiguration cfg;

    //folder pairs:
    //m_directoryLeft, m_directoryRight
    std::vector<FolderPairPanel*> 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<FreeFileSync::FolderPair> getFolderPairs() const;


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

    FreeFileSync::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 currentConfigFileName;

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

    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;

    //support for drag and drop
    std::auto_ptr<MainFolderDragDrop> dragDropOnLeft;
    std::auto_ptr<MainFolderDragDrop> dragDropOnRight;

#ifdef FFS_WIN
    //update icons periodically: one updater instance for both left and right grids
    std::auto_ptr<IconUpdater> updateFileIcons;
#endif

    //encapsulation of handling of sync preview
    std::auto_ptr<SyncPreview> syncPreview;
};


class SyncPreview //encapsulates MainDialog functionality for synchronization preview (friend class)
{
    friend class MainDialog;

public:
    void enablePreview(bool value);
    bool previewIsEnabled();

    void enableSynchronization(bool value);
    bool synchronizationIsEnabled();

private:
    SyncPreview(MainDialog* mainDlg);

    MainDialog* mainDlg_;
    bool syncPreviewEnabled; //toggle to display configuration preview instead of comparison result
    bool synchronizationEnabled; //determines whether synchronization should be allowed
};

#endif // MAINDIALOG_H
bgstack15