Skip to content

Commit

Permalink
Merge pull request #7 from IvoKrugers/develop
Browse files Browse the repository at this point in the history
17.4.1
  • Loading branch information
IvoKrugers authored Nov 8, 2022
2 parents b210ea8 + df97ae1 commit 1773507
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;
using MonoDevelop.Ide.Gui.Pads;
using NetworkExtension;
using VisualStudioMac.OneClickToOpenFile.Extensions;

namespace VisualStudioMac.OneClickToOpenFile.CommandHandlers
{
public class EnableOneClickToOpenFileCommandHandler : CommandHandler
{
protected override void Update(CommandInfo info)
{
info.Enabled = true;
info.Checked = Settings.OneClickToOpenFileEnabled;
}

protected override void Run()
{
Settings.OneClickToOpenFileEnabled = !Settings.OneClickToOpenFileEnabled;

var pad = (SolutionPad)IdeApp.Workbench.Pads.SolutionPad.Content;
if (pad == null)
return;

pad.RefreshTree();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Diagnostics;
using System.IO;
using EnvDTE;
using MonoDevelop.Core;
using MonoDevelop.Ide;
using MonoDevelop.Ide.Gui.Components;
using MonoDevelop.Projects;
Expand All @@ -12,15 +15,53 @@ public override void OnItemSelected()
{
base.OnItemSelected();

if (CurrentNode.DataItem is ProjectFile f)
var selectedNode = Controller.GetSelectedNode();
var control = Controller.Control;

if (CurrentNode.DataItem is ProjectFile f && Settings.OneClickToOpenFileEnabled)
{
string ext = Path.GetExtension(f.FilePath);
if (Constants.ExcludedExtensionsFromOneClick.FindIndex((s) => s == ext) == -1)
{
if (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.Name != f.FilePath.FileName)
IdeApp.Workbench.OpenDocument(f.FilePath, project: null);
var selectedItem = IdeApp.ProjectOperations.CurrentSelectedItem as ProjectFile;

if (IdeApp.IsRunning
&& IdeApp.IsInitialized
&& IdeApp.Workspace.CurrentSelectedSolution != null
&& IdeApp.Workbench.CurrentLayout != null
&& (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.FilePath.FullPath != f.FilePath.FullPath))
{
Debug.WriteLine($"[OnItemSelected]: CurrentNode: {f.FilePath.FileName} - Selected: {CurrentNode.Selected}, CurrentSelectedItem: {selectedItem?.FilePath.FileName ?? ""}, ActiveDocument: {IdeApp.Workbench.ActiveDocument?.Name ?? ""}");


//if (Controller.Control.HasFocus)
//{
IdeApp.Workbench.OpenDocument(f.FilePath, f.Project);
//IdeApp.Workbench.OpenDocument(f.FilePath, f.Project, MonoDevelop.Ide.Gui.OpenDocumentOptions.OpenIfMissing | MonoDevelop.Ide.Gui.OpenDocumentOptions.BringToFront);
//IdeApp.Workbench.OpenDocument(f.FilePath, f.Project, MonoDevelop.Ide.Gui.OpenDocumentOptions.TryToReuseViewer | MonoDevelop.Ide.Gui.OpenDocumentOptions.OpenIfMissing);
//}
return;
}
}
}
}

//public override void RefreshItem()
//{
// base.RefreshItem();
// var selectedNode = Controller.GetSelectedNode();
// var control = Controller.Control;
// var f = CurrentNode.DataItem as ProjectFile;
// var selectedItem = IdeApp.ProjectOperations.CurrentSelectedItem as ProjectFile;

// Debug.WriteLine($"[RefreshItem]: CurrentNode: {f.FilePath.FileName} - Selected: {CurrentNode.Selected}, CurrentSelectedItem: {selectedItem?.FilePath.FileName ?? ""}, ActiveDocument: {IdeApp.Workbench.ActiveDocument?.Name ?? ""}");
//}

//public override void ActivateItem()
//{
// base.ActivateItem();
//}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Threading.Tasks;
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;

namespace VisualStudioMac.OneClickToOpenFile.CommandHandlers
{
public class StartupCommandHandler : CommandHandler
{
protected override void Run()
{
Settings.OneClickToOpenFileEnabled = false;
IdeApp.Workspace.SolutionLoaded += Workspace_SolutionLoaded;
IdeApp.Workspace.SolutionUnloaded += (s, e) => Settings.OneClickToOpenFileEnabled = false;
//IdeApp.Workbench.LayoutChanged += Workbench_LayoutChanged;
//IdeApp.Exiting += (s,e) => Settings.OneClickToOpenFileEnabled = false;
//IdeApp.Workbench.GuiLocked += (s, e) => Settings.OneClickToOpenFileEnabled = false;
//IdeApp.Workbench.GuiUnlocked += (s, e) => Settings.OneClickToOpenFileEnabled = true;
}

private void Workspace_SolutionLoaded(object sender, MonoDevelop.Projects.SolutionEventArgs e)
{
if (e.Solution != null)
{
Task.Delay(10000).ContinueWith(async t =>
{
await t;
Settings.OneClickToOpenFileEnabled = true;
});
}
}
}
}
1 change: 0 additions & 1 deletion VisualStudioMac.OneClickToOpenFile/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{
public static class Constants
{
public const string Version = "17.3.0";
public const string OneClickChar
#if DEBUG
= ">>";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide;
using MonoDevelop.Ide.Gui.Components;
using MonoDevelop.Ide.Gui.Pads;

namespace VisualStudioMac.OneClickToOpenFile.Extensions
{
public static class SolutionPadExtensions
{
public static void RefreshTree(this SolutionPad pad)
{
if (pad == null)
return;

var root = pad.GetRootNode();
if (root != null)
{
pad.GetTreeView().RefreshNode(root);
root.Expanded = true;
}
}

private static ITreeNavigator GetRootNode(this SolutionPad pad)
=> pad.GetTreeView().GetRootNode();

private static ITreeNavigator GetRootNode(this ExtensibleTreeViewController treeview)
{
var pos = treeview.GetRootPosition();
return treeview.GetNodeAtPosition(pos);
}

private static ExtensibleTreeViewController GetTreeView(this SolutionPad pad)
=> pad.Controller;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override bool CanBuildNode(Type dataType)

public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, NodeInfo nodeInfo)
{
if (dataObject is ProjectFile file)
if (dataObject is ProjectFile file && Settings.OneClickToOpenFileEnabled)
{
var ext = Path.GetExtension(file.FilePath);
if (Constants.ExcludedExtensionsFromOneClick.FindIndex((s) => s == ext) == -1)
Expand Down
20 changes: 10 additions & 10 deletions VisualStudioMac.OneClickToOpenFile/Properties/AddinInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using Mono.Addins.Description;
using VisualStudioMac.OneClickToOpenFile;

[assembly: Addin(
Id = "OneClickToOpenFile",
Namespace = "VisualStudioMac",
Version = Constants.Version,
Category = "IDE extensions"
)]
//[assembly: Addin(
// Id = "OneClickToOpenFile",
// Namespace = "VisualStudioMac",
// Version = Constants.Version,
// Category = "IDE extensions"
//)]

[assembly: AddinName("SolutionTree One Click To Open File")]
[assembly: AddinDescription("This extension opens a file with only one click on the solutiontree.\n\nby Ivo Krugers")]
[assembly: AddinAuthor("Ivo Krugers")]
[assembly: AddinUrl("https://github.com/IvoKrugers/VisualStudioMac.OneClickToOpenFile")]
//[assembly: AddinName("One Click To Open File")]
//[assembly: AddinDescription("This extension opens a file with only one click on the solutiontree.\n\nby Ivo Krugers")]
//[assembly: AddinAuthor("Ivo Krugers")]
//[assembly: AddinUrl("https://github.com/IvoKrugers/VisualStudioMac.OneClickToOpenFile")]

[assembly: AddinDependency("::MonoDevelop.Core", MonoDevelop.BuildInfo.Version)]
[assembly: AddinDependency("::MonoDevelop.Ide", MonoDevelop.BuildInfo.Version)]
18 changes: 0 additions & 18 deletions VisualStudioMac.OneClickToOpenFile/Properties/AssemblyInfo.cs

This file was deleted.

48 changes: 48 additions & 0 deletions VisualStudioMac.OneClickToOpenFile/Properties/Manifest.addin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<Addin name = "VSM: One Click To Open File"
id = "OneClickToOpenFile"
namespace = "VisualStudioMac"
author = "Ivo Krugers"
copyright = "MIT X11"
url = "https://github.com/IvoKrugers/VisualStudioMac.OneClickToOpenFile"
description = "This extension opens a file with only one click on the solutiontree.
by Ivo Krugers
"
category = "IDE extensions"
version = "17.4.1">

<!--<Runtime>
<Import assembly="VisualStudioMac.OneClickToOpenFile.dll" />
</Runtime>-->

<!--<Dependencies>
<Addin id="Core" version="17.4"/>
<Addin id="Ide" version="17.4"/>
<Addin id="DotNetCore" version="17.4" />
</Dependencies>-->


<Extension path="/MonoDevelop/Ide/StartupHandlers">
<Class class="VisualStudioMac.OneClickToOpenFile.CommandHandlers.StartupCommandHandler" />
</Extension>

<!-- ProjectPad NodeBuilders -->
<Extension path="/MonoDevelop/Ide/Pads/ProjectPad">
<NodeBuilder class="VisualStudioMac.OneClickToOpenFile.NodeBuilderExtensions.OneClickFileNodeBuilderExt" />
</Extension>

<!-- Commands -->
<Extension path="/MonoDevelop/Ide/Commands">
<Command id="VisualStudioMac.OneClickToOpenFile.EnableOneClickToOpenFileCommandHandler"
_label="One Click To Open File"
defaultHandler="VisualStudioMac.OneClickToOpenFile.CommandHandlers.EnableOneClickToOpenFileCommandHandler" />
</Extension>

<!-- Main Tool Menu Entries -->
<Extension path="/MonoDevelop/Ide/MainMenu/Tools">
<SeparatorItem id="ExtensionSettingsSeparator" insertafter="MonoDevelop.Ide.Commands.EditCommands.MonodevelopPreferences"/>
<CommandItem id="VisualStudioMac.OneClickToOpenFile.EnableOneClickToOpenFileCommandHandler" insertafter="ExtensionSettingsSeparator" />
</Extension>
</Addin>

This file was deleted.

7 changes: 7 additions & 0 deletions VisualStudioMac.OneClickToOpenFile/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VisualStudioMac.OneClickToOpenFile
{
public static class Settings
{
public static bool OneClickToOpenFileEnabled = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudioMac.Sdk" Version="17.0.0-preview.7955" />
<PackageReference Include="Microsoft.VisualStudioMac.Sdk" Version="17.0.0" />

<Reference Include="Xamarin.Mac">
<HintPath>\Applications\Visual Studio %28Preview%http://29.app\Contents\MonoBundle\Xamarin.Mac.dll</HintPath>
<HintPath>\Applications\Visual Studio %28Preview%29.app\Contents\MonoBundle\Xamarin.Mac.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<None Remove="VisualStudioMac.ExtensionHelper" />
<None Remove="VisualStudioMac.ExtensionsHelper" />
<None Remove="Extensions\" />
<None Remove="MonoDevelop.DotNetCore" />
<None Remove="MonoDevelop.MacPlatform" />
<None Remove="MonoDevelop.MonoMac" />
<None Remove="MonoDevelop.Xamarin.Addins.Core" />
<None Remove="MonoDevelop.Xamarin.Ide" />
<None Remove="MonoDevelop.Xamarin.Ide.Mac" />
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>
</Project>
25 changes: 23 additions & 2 deletions pack.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
clear

SCRIPTFILE=$0

Expand All @@ -10,5 +9,27 @@ cd ${PROJECTFOLDER}

pwd

PROJECTFOLDER=$(pwd)

rm *.mpack
mono /Applications/Visual\ Studio.app/Contents/Resources/lib/monodevelop/bin/vstool.exe setup pack ./VisualStudioMac.OneClickToOpenFile/bin/VisualStudioMac.OneClickToOpenFile.dll

# Pack
#mono /Applications/Visual\ Studio\ \(2019\).app/Contents/Resources/lib/monodevelop/bin/vstool.exe setup pack ./VisualStudioMac.OneClickToOpenFile/bin/VisualStudioMac.OneClickToOpenFile.dll
/Applications/Visual\ Studio\ \(Preview\).app/Contents/MacOS/vstool setup pack /Users/ivokrugers/Xamarin_Projects/VisualStudioMac.OneClickToOpenFile/VisualStudioMac.OneClickToOpenFile/bin/VisualStudioMac.OneClickToOpenFile.dll

# Copy to local dir
for filename in /Applications/Visual\ Studio\ \(Preview\).app/*OneClickToOpenFile*.mpack;
do
echo "move $filename"
mv "$filename" .
done

# Uninstall
/Applications/Visual\ Studio\ \(Preview\).app/Contents/MacOS/vstool setup uninstall VisualStudioMac.OneClickToOpenFile -y

# # Install
# for filename in *.mpack;
# do
# echo "$filename"
# /Applications/Visual\ Studio\ \(Preview\).app/Contents/MacOS/vstool setup install "$PROJECTFOLDER/$filename"
# done

0 comments on commit 1773507

Please sign in to comment.