FIX issue #19 where multiple widget values led to bad replacements in the command
[qgit4/redivivus.git] / src / mainimpl.h
blob3089a953965cabd3740e9750f7d18b1c8e75482b
1 /*
2 Author: Marco Costalba (C) 2005-2007
4 Copyright: See COPYING file that comes with this distribution
6 */
7 #ifndef MAINIMPL_H
8 #define MAINIMPL_H
10 #include <QProcess>
11 #include <QRegExp>
12 #include <QDir>
13 #include "exceptionmanager.h"
14 #include "common.h"
15 #include "ui_mainview.h"
17 class QAction;
18 class QCloseEvent;
19 class QComboBox;
20 class QEvent;
21 class QListWidgetItem;
22 class QModelIndex;
23 class QProgressBar;
24 class QShortcutEvent;
25 class QTextEdit;
27 class Domain;
28 class Git;
29 class FileHistory;
30 class FileView;
31 class RevsView;
33 class MainImpl : public QMainWindow, public Ui_MainBase {
34 Q_OBJECT
35 public:
36 MainImpl(const QString& curDir = "", QWidget* parent = 0);
37 void updateContextActions(SCRef newRevSha, SCRef newFileName, bool isDir, bool found);
38 const QString getRevisionDesc(SCRef sha);
39 const QString currentDir() const {return curDir;}
41 // not buildable with Qt designer, will be created manually
42 QLineEdit* lineEditSHA;
43 QLineEdit* lineEditFilter;
45 enum ComboSearch {
46 CS_SHORT_LOG,
47 CS_LOG_MSG,
48 CS_AUTHOR,
49 CS_SHA1,
50 CS_FILE,
51 CS_PATCH,
52 CS_PATCH_REGEXP
55 QComboBox* cmbSearch;
57 signals:
58 void highlightPatch(const QString&, bool);
59 void updateRevDesc();
60 void closeAllWindows();
61 void closeAllTabs();
62 void changeFont(const QFont&);
63 void typeWriterFontChanged();
64 void flagChanged(uint);
66 private slots:
67 void tabWdg_currentChanged(int);
68 void newRevsAdded(const FileHistory*, const QVector<ShaString>&);
69 void fileNamesLoad(int, int);
70 void applyRevisions(const QStringList& shas, const QString& remoteRepo);
71 bool applyPatches(const QStringList &files);
72 void rebase(const QString& from, const QString& to, const QString& onto);
73 void merge(const QStringList& shas, const QString& into);
74 void moveRef(const QString& refName, const QString& toSHA);
75 void shortCutActivated();
77 protected:
78 virtual bool event(QEvent* e);
80 protected slots:
81 void initWithEventLoopActive();
82 void refreshRepo(bool setCurRevAfterLoad = true);
83 void listViewLog_doubleClicked(const QModelIndex&);
84 void fileList_itemDoubleClicked(QListWidgetItem*);
85 void treeView_doubleClicked(QTreeWidgetItem*, int);
86 void histListView_doubleClicked(const QModelIndex&);
87 void customActionListChanged(const QStringList& list);
88 void openRecent_triggered(QAction*);
89 void customAction_triggered(QAction*);
90 void customAction_exited(const QString& name);
91 void goRef_triggered(QAction*);
92 void changesCommitted(bool);
93 void lineEditSHA_returnPressed();
94 void lineEditFilter_returnPressed();
95 void tabBar_tabCloseRequested(int index);
96 void ActBack_activated();
97 void ActForward_activated();
98 void ActFind_activated();
99 void ActFindNext_activated();
100 void ActRangeDlg_activated();
101 void ActViewRev_activated();
102 void ActViewFile_activated();
103 void ActViewFileNewTab_activated();
104 void ActViewDiff_activated();
105 void ActViewDiffNewTab_activated();
106 void ActExternalDiff_activated();
107 void ActExternalEditor_activated();
108 void ActSplitView_activated();
109 void ActToggleLogsDiff_activated();
110 void ActShowDescHeader_activated();
111 void ActOpenRepo_activated();
112 void ActOpenRepoNewWindow_activated();
113 void ActRefresh_activated();
114 void ActSaveFile_activated();
115 void ActMailFormatPatch_activated();
116 void ActMailApplyPatch_activated();
117 void ActSettings_activated();
118 void ActCommit_activated();
119 void ActAmend_activated();
120 void ActCheckout_activated();
121 void ActBranch_activated();
122 void ActTag_activated();
123 void ActDelete_activated();
124 void ActPush_activated();
125 void ActPop_activated();
126 void ActClose_activated();
127 void ActExit_activated();
128 void ActSearchAndFilter_toggled(bool);
129 void ActSearchAndHighlight_toggled(bool);
130 void ActCustomActionSetup_activated();
131 void ActCheckWorkDir_toggled(bool);
132 void ActShowTree_toggled(bool);
133 void ActFilterTree_toggled(bool);
134 void ActAbout_activated();
135 void ActHelp_activated();
136 void ActMarkDiffToSha_activated();
137 void closeEvent(QCloseEvent* ce);
139 private:
140 friend class setRepoDelayed;
142 virtual bool eventFilter(QObject* obj, QEvent* ev);
143 void updateGlobalActions(bool b);
144 void updateRevVariables(SCRef sha);
145 void setupShortcuts();
146 int currentTabType(Domain** t);
147 int tabType(Domain** t, int index);
148 void filterList(bool isOn, bool onlyHighlight);
149 bool isMatch(SCRef sha, SCRef f, int cn, const QMap<QString,bool>& sm);
150 void highlightAbbrevSha(SCRef abbrevSha);
151 void setRepository(SCRef wd, bool = false, bool = false, const QStringList* = NULL, bool = false);
152 void getExternalDiffArgs(QStringList* args, QStringList* filenames);
153 QString copyFileToDiffIfNeeded(QStringList* filenames, QString sha);
154 QStringList getExternalEditorArgs();
155 void lineEditSHASetText(SCRef text);
156 void updateCommitMenu(bool isStGITStack);
157 void updateRecentRepoMenu(SCRef newEntry = "");
158 void doUpdateRecentRepoMenu(SCRef newEntry);
159 void doUpdateCustomActionMenu(const QStringList& list);
160 void doBranchOrTag(bool isTag);
161 void ActCommit_setEnabled(bool b);
162 void doContexPopup(SCRef sha);
163 void doFileContexPopup(SCRef fileName, int type);
164 void adjustFontSize(int delta);
165 void scrollTextEdit(int delta);
166 void goMatch(int delta);
167 bool askApplyPatchParameters(bool* commit, bool* fold);
168 void saveCurrentGeometry();
169 QTextEdit* getCurrentTextEdit();
170 template<class X> QList<X*>* getTabs(QWidget* tabPage = NULL);
171 template<class X> X* firstTab(QWidget* startPage = NULL);
172 void openFileTab(FileView* fv = NULL);
174 EM_DECLARE(exExiting);
176 Git* git;
177 RevsView* rv;
178 QProgressBar* pbFileNamesLoading;
180 // curDir is the repository working directory, could be different from qgit running
181 // directory QDir::current(). Note that qgit could be run from subdirectory
182 // so only after git->isArchive() that updates curDir to point to working directory
183 // we are sure is correct.
184 QString curDir;
185 QString startUpDir;
186 QString startUpFile;
187 QString textToFind;
188 QRegExp shortLogRE;
189 QRegExp longLogRE;
190 static const QRegExp emptySha;
191 QMap<QString, QVariant> revision_variables; // variables used in generic input dialogs
192 bool setRepositoryBusy;
196 class ExternalDiffProc : public QProcess {
197 Q_OBJECT
198 public:
199 ExternalDiffProc(const QStringList& f, QObject* p)
200 : QProcess(p), filenames(f) {
202 connect(this, SIGNAL(finished(int, QProcess::ExitStatus)),
203 this, SLOT(on_finished(int, QProcess::ExitStatus)));
205 ~ExternalDiffProc() {
207 terminate();
208 removeFiles();
210 QStringList filenames;
212 private slots:
213 void on_finished(int, QProcess::ExitStatus) { deleteLater(); }
215 private:
216 void removeFiles() {
218 if (!filenames.empty()) {
219 QDir d; // remove temporary files to diff on
220 for (int i = 0; i < filenames.size(); i++)
222 d.remove(filenames[i]);
228 class ExternalEditorProc : public QProcess {
229 Q_OBJECT
230 public:
231 ExternalEditorProc(QObject* p)
232 : QProcess(p) {
234 connect(this, SIGNAL(finished(int, QProcess::ExitStatus)),
235 this, SLOT(on_finished(int, QProcess::ExitStatus)));
237 ~ExternalEditorProc() {
238 terminate();
241 private slots:
242 void on_finished(int, QProcess::ExitStatus) { deleteLater(); }
244 private:
248 #endif