Merge pull request #191 from ennerperez/feature/q-open-submodule

Quick open submodule
This commit is contained in:
leo 2024-06-20 09:27:48 +08:00 committed by GitHub
commit 02ace694d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 17 deletions

View file

@ -1538,6 +1538,27 @@ namespace SourceGit.ViewModels
return menu; return menu;
} }
public void OpenSubmodule(string submodule)
{
var root = Path.GetFullPath(Path.Combine(_fullpath, submodule));
var gitDir = new Commands.QueryGitDir(root).Result();
var repo = Preference.AddRepository(root, gitDir);
var node = new RepositoryNode()
{
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};
var launcher = App.GetTopLevel().DataContext as Launcher;
if (launcher != null)
{
launcher.OpenRepositoryInTab(node, null);
}
}
public ContextMenu CreateContextMenuForSubmodule(string submodule) public ContextMenu CreateContextMenuForSubmodule(string submodule)
{ {
var open = new MenuItem(); var open = new MenuItem();
@ -1545,23 +1566,7 @@ namespace SourceGit.ViewModels
open.Icon = App.CreateMenuIcon("Icons.Folder.Open"); open.Icon = App.CreateMenuIcon("Icons.Folder.Open");
open.Click += (o, ev) => open.Click += (o, ev) =>
{ {
var root = Path.GetFullPath(Path.Combine(_fullpath, submodule)); OpenSubmodule(submodule);
var gitDir = new Commands.QueryGitDir(root).Result();
var repo = Preference.AddRepository(root, gitDir);
var node = new RepositoryNode()
{
Id = repo.FullPath,
Name = Path.GetFileName(repo.FullPath),
Bookmark = 0,
IsRepository = true,
};
var launcher = App.GetTopLevel().DataContext as Launcher;
if (launcher != null)
{
launcher.OpenRepositoryInTab(node, null);
}
ev.Handled = true; ev.Handled = true;
}; };

View file

@ -457,6 +457,7 @@
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
ContextRequested="OnSubmoduleContextRequested" ContextRequested="OnSubmoduleContextRequested"
DoubleTapped="OnDoubleTappedSubmodule"
IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}"> IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}">
<DataGrid.Styles> <DataGrid.Styles>
<Style Selector="DataGridRow"> <Style Selector="DataGridRow">

View file

@ -332,5 +332,16 @@ namespace SourceGit.Views
outs.Add(b); outs.Add(b);
} }
} }
private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e)
{
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
{
var submodule = datagrid.SelectedItem as string;
(DataContext as ViewModels.Repository).OpenSubmodule(submodule);
}
e.Handled = true;
}
} }
} }