Fuel

Diff
Login

Differences From Artifact [b8d87316df]:

To Artifact [7f3b069531]:


33
34
35
36
37
38
39












































40
41
42
43
44
45
46
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	TAB_BROWSER
};

enum
{
	REPODIRMODEL_ROLE_PATH = Qt::UserRole+1
};

struct TreeViewItem
{
	enum
	{
		TYPE_UNKNOWN,
		TYPE_WORKSPACE,
		TYPE_FOLDER,
		TYPE_STASHES,
		TYPE_STASH,
		TYPE_BRANCHES,
		TYPE_BRANCH,
		TYPE_TAGS,
		TYPE_TAG,
		TYPE_REMOTES,
		TYPE_SETTINGS
	};

	TreeViewItem()
	: Type(TYPE_UNKNOWN)
	{
	}

	TreeViewItem(int type, const QString &value)
	: Type(type), Value(value)
	{
	}

	TreeViewItem(const TreeViewItem &other)
	{
		Type = other.Type;
		Value = other.Value;
	}

	int Type;
	QString Value;

	operator QVariant() const
	{
		return QVariant::fromValue(*this);
	}
};
Q_DECLARE_METATYPE(TreeViewItem)


//-----------------------------------------------------------------------------
typedef QMap<QString, QString> QStringMap;
static QStringMap MakeKeyValues(QStringList lines)
{
	QStringMap res;

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
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







+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+








+
+
+
+
+
+







	// workspaceTreeView
	ui->workspaceTreeView->setModel(&getWorkspace().getDirModel());
	connect( ui->workspaceTreeView->selectionModel(),
		SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
		SLOT( onWorkspaceTreeViewSelectionChanged(const QItemSelection &, const QItemSelection &) ),
		Qt::DirectConnection );

	// Workspace Menus
	menuWorkspace = new QMenu(this);
	ui->workspaceTreeView->addAction(ui->actionCommit);
	ui->workspaceTreeView->addAction(ui->actionOpenFolder);
	ui->workspaceTreeView->addAction(ui->actionAdd);
	ui->workspaceTreeView->addAction(ui->actionRevert);
	ui->workspaceTreeView->addAction(ui->actionDelete);
	ui->workspaceTreeView->addAction(separator);
	ui->workspaceTreeView->addAction(ui->actionRenameFolder);
	ui->workspaceTreeView->addAction(ui->actionOpenFolder);
	menuWorkspace->addAction(ui->actionCommit);
	menuWorkspace->addAction(ui->actionOpenFolder);
	menuWorkspace->addAction(ui->actionAdd);
	menuWorkspace->addAction(ui->actionRevert);
	menuWorkspace->addAction(ui->actionDelete);
	menuWorkspace->addAction(separator);
	menuWorkspace->addAction(ui->actionRenameFolder);
	menuWorkspace->addAction(ui->actionOpenFolder);

	// StashView
	ui->stashTableView->setModel(&getWorkspace().getStashModel());
	ui->stashTableView->addAction(ui->actionApplyStash);
	ui->stashTableView->addAction(ui->actionDiffStash);
	ui->stashTableView->addAction(ui->actionDeleteStash);
	ui->stashTableView->horizontalHeader()->setSortIndicatorShown(false);

	// StashMenu
	menuStashes = new QMenu(this);
	menuStashes->addAction(ui->actionApplyStash);
	menuStashes->addAction(ui->actionDiffStash);
	menuStashes->addAction(ui->actionDeleteStash);

	// Recent Workspaces
	// Locate a sequence of two separator actions in file menu
	QList<QAction*> file_actions = ui->menuFile->actions();
	QAction *recent_sep=0;
	for(int i=0; i<file_actions.size(); ++i)
	{
		QAction *act = file_actions[i];
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608

609
610
611
612
613



614
615
616
617
618
619
620








621
622
623





































624
625

626
627
628
629
630
631
632
638
639
640
641
642
643
644

645
646
647
648
649
650
651
652
653
654
655
656
657
658
659

660
661
662



663
664
665
666






667
668
669
670
671
672
673
674
675


676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721







-
+














-
+


-
-
-
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+







				found = true;
			}
		}

		if(!found) // Generate it
		{
			QStandardItem *child = new QStandardItem(QIcon(":icons/icons/Folder-01.png"), dir);
			child->setData(fullpath); // keep the full path to simplify selection
			child->setData(TreeViewItem(TreeViewItem::TYPE_FOLDER, fullpath), REPODIRMODEL_ROLE_PATH);
			parent->appendRow(child);
			parent = child;
		}
		fullpath += '/';
	}
}

//------------------------------------------------------------------------------
void MainWindow::updateDirView()
{
	// Directory View
	getWorkspace().getDirModel().clear();

	QStringList header;
	header << tr("Folders");
	header << fossil().getProjectName();
	getWorkspace().getDirModel().setHorizontalHeaderLabels(header);

	QStandardItem *root = new QStandardItem(QIcon(":icons/icons/My Documents-01.png"), fossil().getProjectName());
	root->setData(""); // Empty Path
	root->setEditable(false);
	QStandardItem *workspace = new QStandardItem(QIcon(":icons/icons/Folder-01.png"), "Workspace");
	workspace->setData(TreeViewItem(TreeViewItem::TYPE_WORKSPACE, ""), REPODIRMODEL_ROLE_PATH);
	workspace->setEditable(false);

	getWorkspace().getDirModel().appendRow(root);
	for(stringset_t::iterator it = getWorkspace().getPaths().begin(); it!=getWorkspace().getPaths().end(); ++it)
	{
		const QString &dir = *it;
		if(dir.isEmpty())
			continue;
	getWorkspace().getDirModel().appendRow(workspace);
	if(viewMode == VIEWMODE_TREE)
	{
		for(stringset_t::iterator it = getWorkspace().getPaths().begin(); it!=getWorkspace().getPaths().end(); ++it)
		{
			const QString &dir = *it;
			if(dir.isEmpty())
				continue;

		addPathToTree(*root, dir);
	}
			addPathToTree(*workspace, dir);
		}
	}

	QStandardItem *branches = new QStandardItem(QIcon(":icons/icons/Document Organization Chart-01.png"), "Branches");
	branches->setData(TreeViewItem(TreeViewItem::TYPE_BRANCHES, ""), REPODIRMODEL_ROLE_PATH);
	branches->setEditable(false);
	getWorkspace().getDirModel().appendRow(branches);

	QStandardItem *stashes = new QStandardItem(QIcon(":icons/icons/My Documents-01.png"), "Stashes");
	stashes->setData(TreeViewItem(TreeViewItem::TYPE_STASHES, ""), REPODIRMODEL_ROLE_PATH);
	stashes->setEditable(false);
	getWorkspace().getDirModel().appendRow(stashes);
	for(stashmap_t::const_iterator it= getWorkspace().getStashes().begin(); it!=getWorkspace().getStashes().end(); ++it)
	{
		QStandardItem *stash = new QStandardItem(QIcon(":icons/icons/Folder-01.png"), it.key());
		stash->setData(TreeViewItem(TreeViewItem::TYPE_STASH, it.value()), REPODIRMODEL_ROLE_PATH);
		stashes->appendRow(stash);
	}


	QStandardItem *tags = new QStandardItem(QIcon(":icons/icons/Book-01.png"), "Tags");
	tags->setData(TreeViewItem(TreeViewItem::TYPE_TAGS, ""), REPODIRMODEL_ROLE_PATH);
	tags->setEditable(false);
	getWorkspace().getDirModel().appendRow(tags);

	QStandardItem *remotes = new QStandardItem(QIcon(":icons/icons/Network PC-01.png"), "Remotes");
	remotes->setData(TreeViewItem(TreeViewItem::TYPE_REMOTES, ""), REPODIRMODEL_ROLE_PATH);
	remotes->setEditable(false);
	getWorkspace().getDirModel().appendRow(remotes);

	QStandardItem *settings = new QStandardItem(QIcon(":icons/icons/Gear-01.png"), "Settings");
	settings->setData(TreeViewItem(TreeViewItem::TYPE_SETTINGS, ""), REPODIRMODEL_ROLE_PATH);
	settings->setEditable(false);
	getWorkspace().getDirModel().appendRow(settings);


	ui->workspaceTreeView->expandToDepth(0);
	ui->workspaceTreeView->sortByColumn(0, Qt::AscendingOrder);
	//ui->workspaceTreeView->sortByColumn(0, Qt::AscendingOrder);
}

//------------------------------------------------------------------------------
void MainWindow::updateFileView()
{
	// Clear content except headers
	getWorkspace().getFileModel().removeRows(0, getWorkspace().getFileModel().rowCount());
813
814
815
816
817
818
819
820

821
822
823
824
825
826
827
902
903
904
905
906
907
908

909
910
911
912
913
914
915
916







-
+







	if(store->contains("ViewIgnored"))
		ui->actionViewIgnored->setChecked(store->value("ViewIgnored").toBool());
	if(store->contains("ViewAsList"))
	{
		ui->actionViewAsList->setChecked(store->value("ViewAsList").toBool());
		viewMode = store->value("ViewAsList").toBool()? VIEWMODE_LIST : VIEWMODE_TREE;
	}
	ui->workspaceTreeView->setVisible(viewMode == VIEWMODE_TREE);
	//ui->workspaceTreeView->setVisible(viewMode == VIEWMODE_TREE);

	if(store->contains("ViewStash"))
		ui->actionViewStash->setChecked(store->value("ViewStash").toBool());
	ui->stashTableView->setVisible(ui->actionViewStash->isChecked());

}

863
864
865
866
867
868
869

870
871
872
873
874
875
876
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966







+







	store->setValue("ViewAsList", ui->actionViewAsList->isChecked());
	store->setValue("ViewStash", ui->actionViewStash->isChecked());
}

//------------------------------------------------------------------------------
void MainWindow::selectRootDir()
{
	// FIXME: KKK
	if(viewMode==VIEWMODE_TREE)
	{
		QModelIndex root_index = ui->workspaceTreeView->model()->index(0, 0);
		ui->workspaceTreeView->selectionModel()->select(root_index, QItemSelectionModel::Select);
	}
}

902
903
904
905
906
907
908
909

910
911
912
913







914
915
916
917
918
919
920
992
993
994
995
996
997
998

999
1000



1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014







-
+

-
-
-
+
+
+
+
+
+
+







}

//------------------------------------------------------------------------------
void MainWindow::getSelectionPaths(stringset_t &paths)
{
	// Determine the directories selected
	QModelIndexList selection = ui->workspaceTreeView->selectionModel()->selectedIndexes();
	for(QModelIndexList::iterator mi_it = selection.begin(); mi_it!=selection.end(); ++mi_it)
	foreach(const QModelIndex &mi, selection)
	{
		const QModelIndex &mi = *mi_it;
		QVariant data = getWorkspace().getDirModel().data(mi, REPODIRMODEL_ROLE_PATH);
		paths.insert(data.toString());
		QVariant data = Workspace().getDirModel().data(mi, REPODIRMODEL_ROLE_PATH);
		Q_ASSERT(data.isValid());
		TreeViewItem tv = data.value<TreeViewItem>();
		if(tv.Type != TreeViewItem::TYPE_FOLDER)
			continue;

		paths.insert(tv.Value);
	}
}
//------------------------------------------------------------------------------
// Select all workspace files that match the includeMask
void MainWindow::getAllFilenames(QStringList &filenames, int includeMask)
{
	for(Workspace::filemap_t::iterator it=getWorkspace().getFiles().begin(); it!=getWorkspace().getFiles().end(); ++it)
1499
1500
1501
1502
1503
1504
1505

1506


1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523
1524

1525
1526
1527

1528
1529

1530





1531
1532
1533





1534
1535




1536


1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553



1554


1555
1556
1557
1558
1559
1560
1561
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616

1617

1618
1619

1620
1621
1622

1623
1624

1625
1626
1627
1628
1629
1630
1631



1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664

1665
1666
1667
1668
1669
1670
1671
1672
1673







+

+
+













-
+
-


-
+


-
+

-
+

+
+
+
+
+
-
-
-
+
+
+
+
+


+
+
+
+
-
+
+

















+
+
+
-
+
+







	refresh();
}

//------------------------------------------------------------------------------
void MainWindow::on_actionViewAsList_triggered()
{
	viewMode =  ui->actionViewAsList->isChecked() ? VIEWMODE_LIST : VIEWMODE_TREE;
#if 0
	ui->workspaceTreeView->setVisible(viewMode == VIEWMODE_TREE);
#endif
	updateDirView();
	updateFileView();
}

//------------------------------------------------------------------------------
QString MainWindow::getFossilHttpAddress()
{
	QString port = settings.GetValue(FUEL_SETTING_HTTP_PORT).toString();
	return "http://127.0.0.1:"+port;
}

//------------------------------------------------------------------------------
void MainWindow::onWorkspaceTreeViewSelectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{
	QModelIndexList selection = ui->workspaceTreeView->selectionModel()->selectedIndexes();
	QModelIndexList indices = ui->workspaceTreeView->selectionModel()->selectedIndexes();
	int num_selected = selection.count();

	// Do not modify the selection if nothing is selected
	if(num_selected==0)
	if(indices.empty())
		return;

	selectedDirs.clear();
	stringset_t new_dirs;

	for(int i=0; i<num_selected; ++i)
	foreach(const QModelIndex &id, indices)
	{
		Q_ASSERT(ui->workspaceTreeView->model()==&getWorkspace().getDirModel());
		//QVariant data = getWorkspace().getDirModel().data(id, REPODIRMODEL_ROLE_PATH);
		QVariant data = id.model()->data(id, REPODIRMODEL_ROLE_PATH);
		Q_ASSERT(data.isValid());
		TreeViewItem tv = data.value<TreeViewItem>();
		QModelIndex index = selection.at(i);
		QString dir = getWorkspace().getDirModel().data(index, REPODIRMODEL_ROLE_PATH).toString();
		selectedDirs.insert(dir);

		if(tv.Type != TreeViewItem::TYPE_FOLDER && tv.Type != TreeViewItem::TYPE_WORKSPACE)
			continue;

		new_dirs.insert(tv.Value);
	}

	// Update the selection if we have any new folders
	if(!new_dirs.empty() && viewMode == VIEWMODE_TREE)
	{
		selectedDirs = new_dirs;
	updateFileView();
		updateFileView();
	}
}

//------------------------------------------------------------------------------
void MainWindow::on_actionOpenFolder_triggered()
{
	const QItemSelection &selection =  ui->workspaceTreeView->selectionModel()->selection();

	if(selection.indexes().count()!=1)
		return;

	QModelIndex index = selection.indexes().at(0);
	on_workspaceTreeView_doubleClicked(index);
}

//------------------------------------------------------------------------------
void MainWindow::on_workspaceTreeView_doubleClicked(const QModelIndex &index)
{
	QVariant data = index.model()->data(index, REPODIRMODEL_ROLE_PATH);
	Q_ASSERT(data.isValid());
	TreeViewItem tv = data.value<TreeViewItem>();
	QString target = getWorkspace().getDirModel().data(index, REPODIRMODEL_ROLE_PATH).toString();
	QString target = tv.Value;

	target = getCurrentWorkspace() + PATH_SEPARATOR + target;

	QUrl url = QUrl::fromLocalFile(target);
	QDesktopServices::openUrl(url);
}

//------------------------------------------------------------------------------
1912
1913
1914
1915
1916
1917
1918




























1919
1920
1921
1922
1923
1924
1925
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	{
		QMenu *menu = new QMenu(this);
		menu->addActions(ui->fileTableView->actions());
		menu->popup(gpos);
	}

}

//------------------------------------------------------------------------------
void MainWindow::on_workspaceTreeView_customContextMenuRequested(const QPoint &)
{
	QModelIndexList indices = ui->workspaceTreeView->selectionModel()->selectedIndexes();

	if(indices.empty())
		return;

	QMenu *menu = 0;

	// Get first selected item
	const QModelIndex &mi = indices.first();
	QVariant data = getWorkspace().getDirModel().data(mi, REPODIRMODEL_ROLE_PATH);
	Q_ASSERT(data.isValid());
	TreeViewItem tv = data.value<TreeViewItem>();

	if(tv.Type == TreeViewItem::TYPE_FOLDER ||  tv.Type == TreeViewItem::TYPE_WORKSPACE)
		menu = menuWorkspace;
	else if (tv.Type == TreeViewItem::TYPE_STASH || tv.Type == TreeViewItem::TYPE_STASHES)
		menu = menuStashes;

	if(menu)
	{
		QPoint pos = QCursor::pos();
		menu->popup(pos);
	}
}

//------------------------------------------------------------------------------
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
	// Ignore drops from the same window
	if(event->source() != this)
		event->acceptProposedAction();