mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 10:45:39 +03:00
WIP
This commit is contained in:
parent
981adc8c65
commit
31ccf5c7e3
@ -39,8 +39,10 @@ DiffPanel::DiffPanel(const git::Repository &repo, QWidget *parent)
|
||||
connect(context, contextSignal, [this](int value) {
|
||||
mConfig.setValue("diff.context", value);
|
||||
foreach (MainWindow *window, MainWindow::windows()) {
|
||||
for (int i = 0; i < window->count(); ++i)
|
||||
window->view(i)->refresh();
|
||||
for (int i = 0; i < window->count(); ++i) {
|
||||
if (auto v = window->view(i))
|
||||
v->refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -64,8 +66,10 @@ DiffPanel::DiffPanel(const git::Repository &repo, QWidget *parent)
|
||||
}
|
||||
|
||||
foreach (MainWindow *window, MainWindow::windows()) {
|
||||
for (int i = 0; i < window->count(); ++i)
|
||||
window->view(i)->refresh();
|
||||
for (int i = 0; i < window->count(); ++i) {
|
||||
if (auto v = window->view(i))
|
||||
v->refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -165,8 +165,10 @@ public:
|
||||
connect(mFetch, &QCheckBox::toggled, this, [](bool checked) {
|
||||
Settings::instance()->setValue(Setting::Id::FetchAutomatically, checked);
|
||||
foreach (MainWindow *window, MainWindow::windows()) {
|
||||
for (int i = 0; i < window->count(); ++i)
|
||||
window->view(i)->startFetchTimer();
|
||||
for (int i = 0; i < window->count(); ++i) {
|
||||
if (auto v = window->view(i))
|
||||
v->startFetchTimer();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
}
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
|
||||
return mWindow->count() ? dict().size() : 0;
|
||||
return mWindow->repoCount() ? dict().size() : 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -117,7 +117,8 @@ MainWindow::MainWindow(const git::Repository &repo, QWidget *parent,
|
||||
|
||||
if (refresh) {
|
||||
for (int i = 0; i < count(); ++i)
|
||||
view(i)->refresh();
|
||||
if (auto v = view(i))
|
||||
v->refresh();
|
||||
}
|
||||
});
|
||||
|
||||
@ -134,6 +135,7 @@ MainWindow::MainWindow(const git::Repository &repo, QWidget *parent,
|
||||
&MainWindow::updateTabNames);
|
||||
|
||||
setCentralWidget(tabs);
|
||||
tabs->addWelcomeTab();
|
||||
|
||||
if (repo)
|
||||
addTab(repo);
|
||||
@ -167,7 +169,11 @@ RepoView *MainWindow::addTab(const QString &path) {
|
||||
|
||||
TabWidget *tabs = tabWidget();
|
||||
for (int i = 0; i < tabs->count(); i++) {
|
||||
RepoView *view = static_cast<RepoView *>(tabs->widget(i));
|
||||
RepoView *view = dynamic_cast<RepoView *>(tabs->widget(i));
|
||||
if (!view) {
|
||||
// Tab 0 is the welcome tab
|
||||
continue;
|
||||
}
|
||||
if (path == view->repo().dir(false).path()) {
|
||||
tabs->setCurrentIndex(i);
|
||||
return view;
|
||||
@ -190,7 +196,11 @@ RepoView *MainWindow::addTab(const git::Repository &repo) {
|
||||
|
||||
TabWidget *tabs = tabWidget();
|
||||
for (int i = 0; i < tabs->count(); i++) {
|
||||
RepoView *view = static_cast<RepoView *>(tabs->widget(i));
|
||||
RepoView *view = dynamic_cast<RepoView *>(tabs->widget(i));
|
||||
if (!view) {
|
||||
// Tab 0 is the welcome tab
|
||||
continue;
|
||||
}
|
||||
if (dir.path() == view->repo().dir(false).path()) {
|
||||
tabs->setCurrentIndex(i);
|
||||
return view;
|
||||
@ -223,12 +233,14 @@ RepoView *MainWindow::addTab(const git::Repository &repo) {
|
||||
|
||||
int MainWindow::count() const { return tabWidget()->count(); }
|
||||
|
||||
int MainWindow::repoCount() const { return tabWidget()->count() - 1; }
|
||||
|
||||
RepoView *MainWindow::currentView() const {
|
||||
return static_cast<RepoView *>(tabWidget()->currentWidget());
|
||||
return dynamic_cast<RepoView *>(tabWidget()->currentWidget());
|
||||
}
|
||||
|
||||
RepoView *MainWindow::view(int index) const {
|
||||
return static_cast<RepoView *>(tabWidget()->widget(index));
|
||||
return dynamic_cast<RepoView *>(tabWidget()->widget(index));
|
||||
}
|
||||
|
||||
MainWindow *MainWindow::activeWindow() {
|
||||
@ -428,10 +440,12 @@ void MainWindow::updateTabNames() {
|
||||
QList<TabName> fullNames;
|
||||
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
TabName name(view(i)->repo().dir(false).path());
|
||||
if (auto v = view(i)) {
|
||||
TabName name(v->repo().dir(false).path());
|
||||
names[name.name()].append(i);
|
||||
fullNames.append(name);
|
||||
}
|
||||
}
|
||||
|
||||
QHash<QString, QList<int>>::key_iterator first;
|
||||
while ((first = names.keyBegin()) != names.keyEnd()) {
|
||||
@ -543,8 +557,10 @@ void MainWindow::updateWindowTitle(int ahead, int behind) {
|
||||
|
||||
QStringList MainWindow::paths() const {
|
||||
QStringList paths;
|
||||
for (int i = 0; i < count(); ++i)
|
||||
paths.append(view(i)->repo().dir(false).path());
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
if (auto v = view(i))
|
||||
paths.append(v->repo().dir(false).path());
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
RepoView *addTab(const git::Repository &repo);
|
||||
|
||||
int count() const;
|
||||
int repoCount() const;
|
||||
RepoView *currentView() const;
|
||||
RepoView *view(int index) const;
|
||||
|
||||
|
@ -56,6 +56,7 @@ void openCloneDialog(CloneDialog::Kind kind) {
|
||||
QObject::connect(dialog, &CloneDialog::accepted, [dialog] {
|
||||
if (MainWindow *window = MainWindow::open(dialog->path())) {
|
||||
RepoView *view = window->currentView();
|
||||
if (view)
|
||||
view->addLogEntry(dialog->message(), dialog->messageTitle());
|
||||
}
|
||||
});
|
||||
@ -322,8 +323,9 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
return;
|
||||
|
||||
if (MainWindow *win = qobject_cast<MainWindow *>(window)) {
|
||||
if (win->count() > 0) {
|
||||
win->currentView()->close();
|
||||
if (win->count() > 1) {
|
||||
if (auto c = win->currentView())
|
||||
c->close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -439,7 +441,8 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
connect(mFind, &QAction::triggered, [] {
|
||||
QWidget *widget = QApplication::activeWindow();
|
||||
if (MainWindow *window = qobject_cast<MainWindow *>(widget)) {
|
||||
window->currentView()->find();
|
||||
if (auto c = window->currentView())
|
||||
c->find();
|
||||
} else if (EditorWindow *window = qobject_cast<EditorWindow *>(widget)) {
|
||||
window->widget()->find();
|
||||
}
|
||||
@ -450,7 +453,8 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
connect(mFindNext, &QAction::triggered, [] {
|
||||
QWidget *widget = QApplication::activeWindow();
|
||||
if (MainWindow *window = qobject_cast<MainWindow *>(widget)) {
|
||||
window->currentView()->findNext();
|
||||
if (auto c = window->currentView())
|
||||
c->findNext();
|
||||
} else if (EditorWindow *window = qobject_cast<EditorWindow *>(widget)) {
|
||||
window->widget()->findNext();
|
||||
}
|
||||
@ -461,7 +465,8 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
connect(mFindPrevious, &QAction::triggered, [] {
|
||||
QWidget *widget = QApplication::activeWindow();
|
||||
if (MainWindow *window = qobject_cast<MainWindow *>(widget)) {
|
||||
window->currentView()->findPrevious();
|
||||
if (auto c = window->currentView())
|
||||
c->findPrevious();
|
||||
} else if (EditorWindow *window = qobject_cast<EditorWindow *>(widget)) {
|
||||
window->widget()->findPrevious();
|
||||
}
|
||||
@ -753,11 +758,13 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
return;
|
||||
|
||||
RepoView *view = win->currentView();
|
||||
if (view) {
|
||||
foreach (const git::Submodule &submodule, view->repo().submodules()) {
|
||||
QAction *action = mOpenSubmodule->addAction(submodule.name());
|
||||
connect(action, &QAction::triggered,
|
||||
[view, submodule] { view->openSubmodule(submodule); });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Stash
|
||||
@ -893,7 +900,7 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
QAction *diffs = debug->addAction(tr("Load All Diffs"));
|
||||
connect(diffs, &QAction::triggered, [this] {
|
||||
if (MainWindow *win = qobject_cast<MainWindow *>(window())) {
|
||||
RepoView *view = win->currentView();
|
||||
if (RepoView *view = win->currentView()) {
|
||||
CommitList *commits = view->commitList();
|
||||
QAbstractItemModel *model = commits->model();
|
||||
for (int i = 0; i < model->rowCount(); ++i) {
|
||||
@ -902,15 +909,18 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
QAction *walk = debug->addAction(tr("Walk Commits"));
|
||||
connect(walk, &QAction::triggered, [this] {
|
||||
if (MainWindow *win = qobject_cast<MainWindow *>(window())) {
|
||||
git::RevWalk walker = win->currentView()->repo().walker();
|
||||
if (auto c = win->currentView()) {
|
||||
git::RevWalk walker = c->repo().walker();
|
||||
while (git::Commit commit = walker.next())
|
||||
(void)commit;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1132,8 +1142,9 @@ void MenuBar::updateHistory() {
|
||||
|
||||
void MenuBar::updateWindow() {
|
||||
MainWindow *win = qobject_cast<MainWindow *>(window());
|
||||
mPrevTab->setEnabled(win && win->count() > 1);
|
||||
mNextTab->setEnabled(win && win->count() > 1);
|
||||
// First tab is the welcome tab
|
||||
mPrevTab->setEnabled(win && win->count() > 2);
|
||||
mNextTab->setEnabled(win && win->count() > 2);
|
||||
}
|
||||
|
||||
QWidget *MenuBar::window() const {
|
||||
@ -1150,7 +1161,10 @@ QList<RepoView *> MenuBar::views() const {
|
||||
|
||||
QList<RepoView *> repos;
|
||||
for (int i = 0; i < win->count(); i++) {
|
||||
repos.append(win->view(i));
|
||||
auto* view = win->view(i);
|
||||
if (view) {
|
||||
repos.append(view);
|
||||
}
|
||||
}
|
||||
return repos;
|
||||
}
|
||||
|
@ -351,7 +351,9 @@ public:
|
||||
if (!mShowFullPath)
|
||||
return mTabs->tabText(row);
|
||||
|
||||
RepoView *view = static_cast<RepoView *>(mTabs->widget(row));
|
||||
RepoView *view = dynamic_cast<RepoView *>(mTabs->widget(row));
|
||||
if (!view)
|
||||
return QStringLiteral("");
|
||||
return view->repo().dir(false).path();
|
||||
}
|
||||
|
||||
@ -445,7 +447,10 @@ public:
|
||||
if (!mTabs->count())
|
||||
return QVariant();
|
||||
QWidget *widget = mTabs->widget(row);
|
||||
RepoView *view = static_cast<RepoView *>(widget);
|
||||
RepoView *view = dynamic_cast<RepoView *>(widget);
|
||||
if (!view) {
|
||||
return QStringLiteral("");
|
||||
}
|
||||
return view->repo().dir(false).path();
|
||||
}
|
||||
|
||||
@ -492,7 +497,10 @@ public:
|
||||
switch (parent.row()) {
|
||||
case Repo:
|
||||
if (mTabs->count()) {
|
||||
RepoView *view = static_cast<RepoView *>(mTabs->widget(row));
|
||||
RepoView *view = dynamic_cast<RepoView *>(mTabs->widget(row));
|
||||
if (!view) {
|
||||
return QStringLiteral("");
|
||||
}
|
||||
return view->repo().dir(false).path();
|
||||
}
|
||||
|
||||
|
@ -8,17 +8,47 @@
|
||||
//
|
||||
|
||||
#include "TabBar.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
||||
namespace {
|
||||
constexpr auto home_tab_width = 50;
|
||||
}
|
||||
|
||||
TabBar::TabBar(QWidget *parent) : QTabBar(parent) {
|
||||
setAutoHide(true);
|
||||
setDocumentMode(true);
|
||||
}
|
||||
|
||||
void TabBar::mousePressEvent(QMouseEvent* event) {
|
||||
mClickedTabIndex = tabAt(event->pos());
|
||||
QTabBar::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void TabBar::mouseMoveEvent(QMouseEvent* event) {
|
||||
qDebug() << event->pos();
|
||||
// if (mClickedTabIndex == 0/*event->pos().x() <= home_tab_width || tabAt(event->pos()) == 0*/) { //
|
||||
// // Ignoring first tab because this is the welcome tab
|
||||
// return;
|
||||
// }
|
||||
|
||||
// QTabBar::mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
void TabBar::mouseReleaseEvent(QMouseEvent* event) {
|
||||
mClickedTabIndex = -1;
|
||||
QTabBar::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
QSize TabBar::minimumTabSizeHint(int index) const {
|
||||
mCalculatingMinimumSize = true;
|
||||
QSize size = QTabBar::minimumTabSizeHint(index);
|
||||
mCalculatingMinimumSize = false;
|
||||
|
||||
if (index == 0)
|
||||
size.setWidth(home_tab_width);
|
||||
|
||||
// Default Tab just a small tab size on the left
|
||||
return size;
|
||||
}
|
||||
@ -28,7 +58,9 @@ QSize TabBar::tabSizeHint(int index) const {
|
||||
return QTabBar::tabSizeHint(index);
|
||||
|
||||
int height = fontMetrics().lineSpacing() + 12;
|
||||
return QSize(parentWidget()->width() / count() + 1, height);
|
||||
if (index == 0)
|
||||
return QSize(home_tab_width, height);
|
||||
return QSize(parentWidget()->width() / (count() - 1) + 1 - home_tab_width, height);
|
||||
|
||||
// Default Tab just a small tab size on the left
|
||||
}
|
||||
|
@ -19,10 +19,14 @@ public:
|
||||
TabBar(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
QSize minimumTabSizeHint(int index) const override;
|
||||
QSize tabSizeHint(int index) const override;
|
||||
|
||||
private:
|
||||
int mClickedTabIndex = -1;
|
||||
mutable bool mCalculatingMinimumSize = false;
|
||||
};
|
||||
|
||||
|
@ -43,9 +43,10 @@ public:
|
||||
connect(clone, &QPushButton::clicked, [this] {
|
||||
CloneDialog *dialog = new CloneDialog(CloneDialog::Clone, this);
|
||||
connect(dialog, &CloneDialog::accepted, [dialog] {
|
||||
if (MainWindow *window = MainWindow::open(dialog->path()))
|
||||
window->currentView()->addLogEntry(dialog->message(),
|
||||
dialog->messageTitle());
|
||||
if (MainWindow *window = MainWindow::open(dialog->path())) {
|
||||
if (auto c = window->currentView())
|
||||
c->addLogEntry(dialog->message(), dialog->messageTitle());
|
||||
}
|
||||
});
|
||||
dialog->open();
|
||||
});
|
||||
@ -70,8 +71,8 @@ public:
|
||||
CloneDialog *dialog = new CloneDialog(CloneDialog::Init, this);
|
||||
connect(dialog, &CloneDialog::accepted, [dialog] {
|
||||
if (MainWindow *window = MainWindow::open(dialog->path()))
|
||||
window->currentView()->addLogEntry(dialog->message(),
|
||||
dialog->messageTitle());
|
||||
if (auto c = window->currentView())
|
||||
c->addLogEntry(dialog->message(), dialog->messageTitle());
|
||||
});
|
||||
dialog->open();
|
||||
});
|
||||
@ -140,13 +141,10 @@ private:
|
||||
|
||||
TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) {
|
||||
TabBar *bar = new TabBar(this);
|
||||
bar->setMovable(true);
|
||||
bar->setMovable(false);
|
||||
bar->setTabsClosable(true);
|
||||
setTabBar(bar);
|
||||
|
||||
// Create default widget.
|
||||
addTab(new DefaultWidget(this), tr("Home"));
|
||||
|
||||
// Handle tab close.
|
||||
connect(this, &TabWidget::tabCloseRequested, [this](int index) {
|
||||
emit tabAboutToBeRemoved();
|
||||
@ -154,6 +152,13 @@ TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) {
|
||||
});
|
||||
}
|
||||
|
||||
void TabWidget::addWelcomeTab() {
|
||||
// Create default widget.
|
||||
addTab(new DefaultWidget(this), tr("Home"));
|
||||
Q_ASSERT(count() == 1);
|
||||
tabBar()->setTabButton(0, QTabBar::RightSide, nullptr);
|
||||
}
|
||||
|
||||
void TabWidget::resizeEvent(QResizeEvent *event) {
|
||||
QTabWidget::resizeEvent(event);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ class TabWidget : public QTabWidget {
|
||||
|
||||
public:
|
||||
TabWidget(QWidget *parent = nullptr);
|
||||
void addWelcomeTab();
|
||||
|
||||
signals:
|
||||
void tabAboutToBeInserted();
|
||||
|
Loading…
Reference in New Issue
Block a user