Skip to content

Commit e59415e

Browse files
author
xujinkai
committed
Support MenuSeparator; Support wildcard syntax; support shortcut key
1 parent ba512ea commit e59415e

15 files changed

Lines changed: 163 additions & 107 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Customize your context menu by Single file.
44

55
![](/docs/screenshot.png)
66

7-
### Feature
7+
## Feature
88

99
- Custom one folder's context menu by `.shellcommand.yaml`
1010
- Custom global context menu by `global.shellcommand.yaml`
11+
- Command Support %DIR% variable
12+
- Command Support Wildcard syntax !?*
1113

1214
## Usage
1315

ShellCommand/.shellcommand.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

ShellCommand/DataModel/DirectoryCommand.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Text;
56
using System.Windows;
67
using System.Windows.Forms;
@@ -36,21 +37,39 @@ public void Execute(string workingDir)
3637
}
3738
}
3839

39-
public ToolStripMenuItem ToMenuItem(string workingDir)
40+
public bool IsMatch(string workingDir)
4041
{
41-
var item = new ToolStripMenuItem(string.IsNullOrEmpty(Name) ? Command : Name);
42+
if (string.IsNullOrEmpty(Match))
43+
return true;
44+
45+
bool reverse = false;
46+
string pattern = Match;
47+
if (Match.StartsWith("!"))
48+
{
49+
reverse = true;
50+
pattern = Match.Substring(1);
51+
}
52+
53+
var exist = Directory.GetFiles(workingDir, pattern).Any() || Directory.GetDirectories(workingDir, pattern).Any();
54+
return exist ^ reverse;
55+
}
56+
57+
public ToolStripItem ToMenuItem(string workingDir)
58+
{
59+
if(string.IsNullOrEmpty(Command) && Name == Env.VAR_SEPNAME)
60+
{
61+
return new ToolStripSeparator();
62+
}
63+
64+
var display = string.IsNullOrEmpty(Name) ? Command : Name;
65+
var item = new ToolStripMenuItem(display)
66+
{
67+
Enabled = IsMatch(workingDir),
68+
};
4269
item.Click += (sender, args) =>
4370
{
4471
Execute(workingDir);
4572
};
46-
if (!string.IsNullOrEmpty(Match))
47-
{
48-
var matchPath = Path.Combine(workingDir, Match);
49-
if (!File.Exists(matchPath) && !Directory.Exists(matchPath))
50-
{
51-
item.Enabled = false;
52-
}
53-
}
5473
return item;
5574
}
5675
}

ShellCommand/DataModel/GlobalConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public class GlobalConfig
1717
public class BuildinFunctions
1818
{
1919
public bool CopyPath { get; set; }
20+
public bool EditGlobal { get; set; }
2021
}
2122
}

ShellCommand/Env.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ namespace ShellCommand
99
public static class Env
1010
{
1111
public const string AppName = "ShellCommand";
12+
public const string MenuDisplay = AppName + "(&C)";
1213
public const string CommandFileName = ".shellcommand.yaml";
1314
public const string GlobalSettingFileName= "global.shellcommand.yaml";
1415
public const string GlobalTemplateSettingFileName = "global.template.shellcommand.yaml";
1516

1617
public const string CreateFolderSpecificFileText = "Create .shellcommand.yaml";
1718
public const string OpenGlobalSettingFileText = "Edit Global Setting";
18-
public const string OpenAppText = "Setting";
19+
public const string OpenAppText = "Open ShellCommand";
1920

2021
public const string ConfigTitle = "# ShellCommand: https://github.com/XUJINKAI/ShellCommand \r\n\r\n";
2122

2223
public const string VAR_DIR = "%DIR%";
24+
public const string VAR_SEPNAME = "---";
2325

2426
public static string GetAppFolder()
2527
{

ShellCommand/LoggingOff.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ServerRegistrationManager.exe config LoggingMode 0

ShellCommand/LoggingOn.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ServerRegistrationManager.exe config LoggingMode 6

ShellCommand/MainWindow.xaml.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using ShellCommand.DataModel;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -61,6 +62,17 @@ private void Install(object sender, RoutedEventArgs e)
6162
{
6263
Cmd.RunAsAdmin(XJK.ENV.EntryLocation, ARG_INSTALL);
6364
}
65+
66+
var globalfile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
67+
if (!File.Exists(globalfile))
68+
{
69+
var templatefile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalTemplateSettingFileName);
70+
if (File.Exists(templatefile))
71+
{
72+
var templateObj = Util.Yaml.LoadYaml<GlobalConfig>(templatefile);
73+
Util.Yaml.SaveYaml(globalfile, templateObj);
74+
}
75+
}
6476
}
6577

6678
private void Uninstall(object sender, RoutedEventArgs e)
@@ -77,13 +89,6 @@ private void Uninstall(object sender, RoutedEventArgs e)
7789

7890
private void AdminInstall()
7991
{
80-
var globalfile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
81-
if (!File.Exists(globalfile))
82-
{
83-
var templatefile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalTemplateSettingFileName);
84-
if (File.Exists(templatefile))
85-
File.Copy(templatefile, globalfile);
86-
}
8792
Util.Reg.SetExePath(XJK.ENV.EntryLocation);
8893
Util.Reg.SetLogPath();
8994
Cmd.RunAsInvoker(Env.GetSrmPath(), "install ShellCommand.exe -codebase");

ShellCommand/MenuDefinition/BuildinMenuItems.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ public static ToolStripMenuItem OpenGlobalSetting()
4747

4848
public static ToolStripMenuItem OpenApp()
4949
{
50-
var path = Util.Reg.GetExePath();
51-
var cmd = new DirectoryCommand()
50+
var item = new ToolStripMenuItem(Env.OpenAppText);
51+
item.Click += (sender, args) =>
5252
{
53-
Name = Env.OpenAppText,
54-
Command = path,
53+
Cmd.RunAsInvoker(Util.Reg.GetExePath(), "");
5554
};
56-
return cmd.ToMenuItem(Path.GetDirectoryName(path));
55+
return item;
5756
}
5857

5958
}

ShellCommand/MenuDefinition/CommandFileParser.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)