Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ Run the same commands from PowerShell in the folder containing `WindowTabs.exe`:
.\WindowTabs.exe --workspace "Project A"
.\WindowTabs.exe --group "C:\Program Files\App\app.exe" notepad.exe
.\WindowTabs.exe --commands
.\WindowTabs.exe --workspaces
```

`--group` starts the programs and puts the windows they open into one group, and
`--workspace` restores a saved workspace; either also starts WindowTabs when it is not
running. `--commands` lists every command with its id.
running. `--commands` lists every command with its id, and `--workspaces` lists every saved
workspace name.

## Settings and updates

Expand Down
24 changes: 22 additions & 2 deletions WtProgram/CommandLine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open System.IO.Pipes
open System.Runtime.InteropServices
open System.Text
open System.Threading
open Bemo.Json

/// What a command line asks for.
type CommandLineRequest =
Expand All @@ -18,6 +19,7 @@ type CommandLineRequest =
/// Starts the programs and puts the windows they open into one group.
| StartGroup of paths:string list
| ListCommands
| ListWorkspaces
| Help
| Invalid of string

Expand All @@ -30,12 +32,13 @@ module CommandLine =
| ("--workspace" | "-w")::name when not name.IsEmpty -> RestoreWorkspace(String.Join(" ",name))
| ("--group" | "-g")::paths when not paths.IsEmpty -> StartGroup paths
| ["--commands"] | ["--list"] -> ListCommands
| ["--workspaces"] -> ListWorkspaces
| ["--help"] | ["-h"] | ["/?"] -> Help
| other -> Invalid(String.Join(" ",other))
let usage() = tr Strings.CommandLine.usage
/// The options a command line may begin with, the long ones offered when one is mistyped.
let private options = ["--command";"-c";"--workspace";"-w";"--group";"-g";"--commands";"--list";"--help";"-h";"/?";"--restart"]
let private longOptions = ["--command";"--workspace";"--group";"--commands";"--help"]
let private options = ["--command";"-c";"--workspace";"-w";"--group";"-g";"--commands";"--list";"--workspaces";"--help";"-h";"/?";"--restart"]
let private longOptions = ["--command";"--workspace";"--group";"--commands";"--workspaces";"--help"]
let private distance (a:string) (b:string) =
let row = Array.init (b.Length+1) id
for i in 1..a.Length do
Expand Down Expand Up @@ -65,6 +68,23 @@ module CommandLine =
Commands.all |> List.filter(fun command -> command.listed)
|> List.map(fun command -> sprintf "%-28s %s" command.id (tr command.text.caption))
|> String.concat Environment.NewLine
/// Every saved workspace's name, one per line, from a settings JSON object.
let workspaceListing (root:JObject) =
let workspaces,_,unsupported = WorkspaceData.read root
if unsupported then ""
else
workspaces
|> List.choose(fun ws -> ws.getString("name"))
|> String.concat Environment.NewLine
/// Saved workspace names read from disk when no running copy answers the pipe.
let savedWorkspaces (isStandAlone:bool) =
try
let settingsPath,legacyPath = SettingsPaths.resolve isStandAlone
use store = new SettingsFileStore(settingsPath,250,ignore,legacyPath)
match store.Read() with
| Some text -> workspaceListing (JObject.Parse(text))
| None -> ""
with _ -> ""

/// The console the program was started from, when there is one: a window program has none of
/// its own, so what the command line asks to see is written there.
Expand Down
9 changes: 9 additions & 0 deletions WtProgram/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ type Program(lifetime:LifetimeScope, ?settings:Settings) as this =
else Result.Error (tr (Strings.CommandLine.noSuchWorkspace name))
| StartGroup paths -> this.launchGroup paths; Result.Ok ""
| ListCommands -> Result.Ok (CommandLine.listing())
| ListWorkspaces -> this.workspaceSummaries() |> List.map fst |> String.concat Environment.NewLine |> Result.Ok
| Invalid given -> Result.Error (CommandLine.invalid given)
| Start | Restart | Help -> Result.Ok (CommandLine.usage())

Expand Down Expand Up @@ -2139,6 +2140,14 @@ module Bootstrap =
| ListCommands ->
ConsoleOutput.write (CommandLine.listing())
0
| ListWorkspaces ->
match CommandPipe.send CommandPipe.name argv 3000 with
| Some(Result.Ok text) -> (if text<>"" then ConsoleOutput.write text); 0
| Some(Result.Error text) -> ConsoleOutput.write text; 1
| None ->
let text = CommandLine.savedWorkspaces Diagnostics.Debugger.IsAttached
if text<>"" then ConsoleOutput.write text
0
| _ ->
use instance = new SingleInstance("BemoSoftware.WindowTabs")
// Starting WindowTabs again replaces the running copy, whichever build or folder either
Expand Down
33 changes: 18 additions & 15 deletions WtProgram/Settings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ open System.IO
open System.Windows.Forms
open Microsoft.FSharp.Reflection
open Bemo.Json


module SettingsPaths =
let resolve (isStandAlone:bool) =
let fileName = "WindowTabsSettings.json"
/// The name older versions use: still read when no .json file exists yet, never written.
let legacyFileName = "WindowTabsSettings.txt"
// Resolved once, so a later working-directory change cannot redirect pending saves.
// A debug or test run (standalone) keeps its file in the working directory. Otherwise a file
// next to WindowTabs.exe makes that copy portable; this used to look in the working
// directory, which is not the exe's folder when Windows starts the app at sign-in.
let exeFolder = AppDomain.CurrentDomain.BaseDirectory
let folder =
if isStandAlone then Path.GetFullPath(".")
elif File.Exists(Path.Combine(exeFolder,fileName)) || File.Exists(Path.Combine(exeFolder,legacyFileName)) then exeFolder
else Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"WindowTabs")
Path.GetFullPath(Path.Combine(folder,fileName)),Path.GetFullPath(Path.Combine(folder,legacyFileName))

type Settings(isStandAlone, ?saveDelay:int) as this =
let mutable cachedSettingsString = None
let mutable cachedSettingsRec = None
Expand All @@ -17,20 +33,7 @@ type Settings(isStandAlone, ?saveDelay:int) as this =
let valueCache = Dictionary<string, obj>()
// Values already handed to other threads; cleared on every write, like valueCache.
let published = Collections.Concurrent.ConcurrentDictionary<string, obj>()
let fileName = "WindowTabsSettings.json"
/// The name older versions use: still read when no .json file exists yet, never written.
let legacyFileName = "WindowTabsSettings.txt"
// Resolved once, so a later working-directory change cannot redirect pending saves.
// A debug or test run (standalone) keeps its file in the working directory. Otherwise a file
// next to WindowTabs.exe makes that copy portable; this used to look in the working
// directory, which is not the exe's folder when Windows starts the app at sign-in.
let exeFolder = AppDomain.CurrentDomain.BaseDirectory
let folder =
if isStandAlone then Path.GetFullPath(".")
elif File.Exists(Path.Combine(exeFolder,fileName)) || File.Exists(Path.Combine(exeFolder,legacyFileName)) then exeFolder
else Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"WindowTabs")
let settingsPath = Path.GetFullPath(Path.Combine(folder,fileName))
let legacyPath = Path.GetFullPath(Path.Combine(folder,legacyFileName))
let settingsPath,legacyPath = SettingsPaths.resolve isStandAlone
let store = new SettingsFileStore(settingsPath,defaultArg saveDelay 250,(fun ex ->
Alert.show AlertKind.Warning (tr Strings.Messages.settingsSaveFailed) (tr (Strings.Messages.unableToSaveSettings settingsPath ex.Message))),
legacyPath)
Expand Down
Loading