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 WtProgram/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ module Commands =
match Services.tryGet<ISplitPanePicker>() with
| Some picker when not entries.IsEmpty ->
let mutable target : IGroup option = None
picker.showForMerge(owner,prompt,entries,fun hwnd ->
picker.showForMerge(owner,prompt,tr Strings.TabMenu.createGroupCount,entries,fun hwnd ->
if WinUserApi.IsWindow hwnd then
let group =
match target with
Expand All @@ -494,6 +494,8 @@ module Commands =
Services.desktop.addExistingWindow(group.hwnd,hwnd))
| Some _ -> Notice.show prompt (tr Strings.TabMenu.splitNoWindows)
| None -> ()) with scope=Everywhere }
{ plain "close-windows" { caption=Strings.TabMenu.closeWindows; description=Strings.TabMenu.closeWindows; keywords=Strings.Commands.closeAllTabs.keywords } TabCommands always (fun owner ->
Services.tryGet<IWindowClosePicker>() |> Option.iter(fun picker -> picker.show(owner,Services.program.windowCandidates None))) with scope=Everywhere }
plain "add-existing-window" Strings.Commands.addExisting GroupCommands hasGroup (onGroup(fun g -> g.run AddExistingWindow))
plain "sort-tabs" Strings.Commands.sortTabs TabCommands hasOtherTabs (onGroup(fun g -> g.run SortTabs))
plain "close-other-tabs" Strings.Commands.closeOtherTabs TabCommands hasOtherTabs (onTab(fun g hwnd -> g.run(CloseOtherTabs hwnd)))
Expand Down
28 changes: 28 additions & 0 deletions WtProgram/ManagerViewService/SettingsEditors.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SettingsActionButton() as this =
let mutable mousePressed = false
let mutable keyPressed = false
let mutable kind = SettingsButtonKind.Standard
let mutable shortcutText = ""
/// A − or + drawn as strokes on the button's middle: as text, the font's ascent and side
/// bearings set them a pixel or two off it.
let mutable sign : char option = None
Expand All @@ -29,6 +30,8 @@ type SettingsActionButton() as this =
this.FlatAppearance.BorderSize <- 0
this.SetStyle(ControlStyles.UserPaint ||| ControlStyles.OptimizedDoubleBuffer ||| ControlStyles.AllPaintingInWmPaint,true)
member this.Kind with get() = kind and set value = kind <- value; this.Invalidate()
/// An optional keyboard hint, separate from the action label.
member this.ShortcutText with get() = shortcutText and set value = shortcutText <- value; this.Invalidate()
/// '−' or '+', drawn in place of the text, which stays for screen readers.
member this.Sign with get() = defaultArg sign ' ' and set (value:char) = sign <- (if value='−' || value='+' then Some value else None); this.Invalidate()
/// Held down by the mouse while over the button, or by Space, as a click is about to happen.
Expand Down Expand Up @@ -117,6 +120,31 @@ type SettingsActionButton() as this =
if symbol='+' then
let down = 2*arm+h%2
e.Graphics.FillRectangle(ink,(w-stroke)/2,(h-down)/2,stroke,down)
| None when shortcutText<>"" ->
use hintFont = new Font(this.Font.FontFamily,this.Font.SizeInPoints*0.9f,FontStyle.Regular,GraphicsUnit.Point)
let padding = Dpi.scale 8
let gap = Dpi.scale 4
let capHeight = min (Dpi.scale 20) (this.Height-Dpi.scale 8)
let keys = shortcutText.Split([|'+'|],StringSplitOptions.RemoveEmptyEntries) |> Array.map(fun key -> key.Trim())
let flags = TextFormatFlags.NoPrefix ||| TextFormatFlags.NoPadding ||| TextFormatFlags.SingleLine
let widths = keys |> Array.map(fun key -> max capHeight (TextRenderer.MeasureText(key,hintFont,Size.Empty,flags).Width+Dpi.scale 10))
let hintWidth = Array.sum widths + max 0 (keys.Length-1)*gap
let mutable x = this.Width-padding-hintWidth
let textBounds = Rectangle(Dpi.scale 10,0,max 0 (x-Dpi.scale 18),this.Height)
TextRenderer.DrawText(e.Graphics,this.Text,this.Font,textBounds,textColor,
TextFormatFlags.NoPrefix ||| TextFormatFlags.VerticalCenter ||| TextFormatFlags.SingleLine ||| TextFormatFlags.EndEllipsis)
let capColor = if highContrast then fillColor else mix fillColor textColor (if this.Enabled then 0.16f else 0.07f)
use capFill = new SolidBrush(capColor)
for key,width in Array.zip keys widths do
let bounds = Rectangle(x,(this.Height-capHeight)/2,width,capHeight)
use cap = SettingsShapes.rounded (RectangleF(float32 bounds.X,float32 bounds.Y,float32 bounds.Width,float32 bounds.Height)) (float32 (Dpi.scale 4))
e.Graphics.FillPath(capFill,cap)
if highContrast then
use border = new Pen(textColor)
e.Graphics.DrawPath(border,cap)
TextRenderer.DrawText(e.Graphics,key,hintFont,bounds,textColor,
flags ||| TextFormatFlags.HorizontalCenter ||| TextFormatFlags.VerticalCenter)
x <- x+width+gap
| None ->
TextRenderer.DrawText(e.Graphics,this.Text,this.Font,this.ClientRectangle,textColor,
TextFormatFlags.NoPrefix ||| TextFormatFlags.HorizontalCenter ||| TextFormatFlags.VerticalCenter ||| TextFormatFlags.EndEllipsis)
Expand Down
1 change: 1 addition & 0 deletions WtProgram/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ type Program(lifetime:LifetimeScope, ?settings:Settings) as this =
Services.register(DispatchedManagerView(ManagerViewService(), dispatcher) :> IManagerView)
// Not dispatched: it builds its drop-down on the group thread that opens it.
Services.register(SplitPanePicker() :> ISplitPanePicker)
Services.register(SplitPanePicker() :> IWindowClosePicker)
SettingsAlert.install()
plugins.iter(fun plugin ->
match plugin with
Expand Down
7 changes: 7 additions & 0 deletions WtProgram/Shared/Strings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ module Strings =
let pickToggle = { en="Toggle"; zh="增减选择"; ja="選択切替"; ar="تبديل"; ko="선택 전환" }
let pickMultiple = { en="Multi-select"; zh="多选"; ja="複数選択"; ar="تحديد متعدد"; ko="다중 선택" }
let pickRange = { en="Range"; zh="连续选择"; ja="範囲選択"; ar="تحديد نطاق"; ko="범위 선택" }
let closeWindows = { en="Close windows…"; zh="关闭窗口…"; ja="ウィンドウを閉じる…"; ar="إغلاق النوافذ…"; ko="창 닫기…" }
let addSelectedCount = { en="Add selected ({0})"; zh="添加所选({0})"; ja="選択を追加 ({0})"; ar="إضافة المحدد ({0})"; ko="선택한 창 추가 ({0})" }
let createGroupCount = { en="New group ({0})"; zh="新建分组({0})"; ja="新しいグループ ({0})"; ar="مجموعة جديدة ({0})"; ko="새 그룹 ({0})" }
let addToWindowGroup = { en="Add to the group containing: {0}"; zh="添加到此窗口所在的组:{0}"; ja="このウィンドウのグループに追加:{0}"; ar="إضافة إلى مجموعة النافذة: {0}"; ko="이 창이 속한 그룹에 추가: {0}" }
let closeSelectedCount = { en="Close selected ({0})"; zh="关闭所选({0})"; ja="選択を閉じる ({0})"; ar="إغلاق المحدد ({0})"; ko="선택한 창 닫기 ({0})" }
let selectionHidden = { en="{0} selected outside these results"; zh="其中 {0} 个不在当前结果中"; ja="選択した {0} 件は検索結果外です"; ar="{0} محددة خارج هذه النتائج"; ko="선택한 창 중 {0}개가 검색 결과 밖에 있음" }
let pinnedProtected = { en="Pinned — protected"; zh="已固定 · 受保护"; ja="固定済み・保護中"; ar="مثبتة — محمية"; ko="고정됨 · 보호됨" }
let confirmSelection = { en="Confirm"; zh="确认"; ja="確定"; ar="تأكيد"; ko="확인" }
let addExisting = { en="Add an existing window"; zh="添加已有窗口"; ja="既存のウィンドウを追加"; ar="إضافة نافذة موجودة"; ko="기존 창 추가" }
let splitSearch = { en="Type a title or app name to fill the pane"; zh="输入标题或应用名,放入这个窗格"; ja="タイトルやアプリ名を入力してペインに配置"; ar="اكتب عنوانًا أو اسم تطبيق لملء الجزء"; ko="제목이나 앱 이름을 입력해 창 영역 채우기" }
Expand Down
21 changes: 19 additions & 2 deletions WtProgram/SplitPanePicker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,26 @@ type SplitPanePicker() =
let search = TabSearchForm(entries,[],pick=choose,within=within,prompt=prompt,
rows=rows,width=width)
search.Show()
interface IWindowClosePicker with
member _.show(owner,windows) =
let identity hwnd =
let mutable pid = 0
let tid = WinUserApi.GetWindowThreadProcessId(hwnd,&pid)
pid,tid
let identities = windows |> List.map(fun (hwnd,_,_) -> hwnd,identity hwnd) |> Map.ofList
let close selected =
for hwnd in selected do
if WinUserApi.IsWindow hwnd && not(PinnedTabs.contains hwnd) && identity hwnd=identities.[hwnd] then
OS().windowFromHwnd(hwnd).close()
let search = TabSearchForm(SplitPaneList.entries windows,[],pickMany=close,
confirmText=(fun count -> String.Format(tr Strings.TabMenu.closeSelectedCount,count)),
blocked=PinnedTabs.contains,prompt=tr Strings.TabMenu.closeWindows,screen=Screen.FromHandle(owner))
search.Show()
interface ISplitPanePicker with
member _.show(owner,_,windows,choose) = open' (owner.RectangleToScreen(owner.ClientRectangle)) (tr Strings.TabMenu.splitSearch) windows choose
member _.showForMerge(strip,prompt,windows,choose) =
let search = TabSearchForm(SplitPaneList.entries windows,[],pickMany=List.iter choose,prompt=prompt,screen=Screen.FromHandle(strip))
member _.showForMerge(strip,prompt,confirmText,windows,choose) =
let search = TabSearchForm(SplitPaneList.entries windows,[],pickMany=List.iter choose,
confirmText=(fun count -> String.Format(confirmText,count)),
prompt=prompt,screen=Screen.FromHandle(strip))
search.Show()
member _.showWithin(within,prompt,windows,choose) = open' within prompt windows choose
5 changes: 4 additions & 1 deletion WtProgram/SplitViewChrome.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ module SplitMenu =

/// Lists windows for a pane to take. Registered by the program with the settings window's
/// drop-down; the picker builds its controls on the calling thread.
type IWindowClosePicker =
abstract member show : owner:IntPtr * windows:(IntPtr * string * string) list -> unit

type ISplitPanePicker =
/// Opens below `anchor`, on screen; `choose` receives the window picked.
abstract member show : owner:Control * anchor:Rectangle * windows:(IntPtr * string * string) list * choose:(IntPtr -> unit) -> unit
abstract member showForMerge : strip:IntPtr * prompt:string * windows:(IntPtr * string * string) list * choose:(IntPtr -> unit) -> unit
abstract member showForMerge : strip:IntPtr * prompt:string * confirmText:string * windows:(IntPtr * string * string) list * choose:(IntPtr -> unit) -> unit
/// Opens over `within`, on screen, as for a group about to split.
abstract member showWithin : within:Rectangle * prompt:string * windows:(IntPtr * string * string) list * choose:(IntPtr -> unit) -> unit

Expand Down
Loading