Skip to content

Commit

Permalink
Redid #18 for menu and command enablers/disablers.
Browse files Browse the repository at this point in the history
LeoInteg is now much more aware of Leo's states and only shows relevant commands
Fixes #30
Adds hoist dehoist. Fixes Add hoist/dehoist commands #25
Move with arrow keys alone Fixes #43
Fixes Force redraw/refresh for icons to update in the outline after a configuration change #16
  • Loading branch information
boltex committed Jul 8, 2020
1 parent d82768a commit 418acb6
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 171 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.1.13

- Added support for precise focus placement, focus switch between tree/body.
- Made the extension more aware of the current selection state, to have strictly relevant buttons visible shown only.
- Made the 'edit headline' hover icon removable, in order to enable 'Tab' keybinding to go from tree to body directly.
- Added commands and keybindings for 'goto' operations 'hoist/dehoist' [#25](https://github.com/boltex/leointeg/issues/25) and other commands. [#30](https://github.com/boltex/leointeg/issues/30)
- Added support for Leo-Style outline navigation. [#43](https://github.com/boltex/leointeg/issues/43) Has to be enabled with an option in the config settings: "Use Leo Tree Browsing" which makes arrow keys move selection instead of a cursor when focus is on the tree outline.
Expand Down
10 changes: 4 additions & 6 deletions leoInteg.leo
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ To contribute, see the official issues page for current list of 'TODO's at https
return self.outputPNodes([]) # default empty array
else:
if self.commander.hoistStack:
w_p = self.commander.hoistStack[-1].p
if w_p:
return self.outputPNodes([w_p])
else:
return self.outputPNodes([]) # default empty array
return self.outputPNodes([self.commander.hoistStack[-1].p])
else:
return self.outputPNodes(self.yieldAllRootChildren()) # this outputs all Root Children

Expand Down Expand Up @@ -466,7 +462,7 @@ if __name__ == '__main__':
'headline': stack_v.h,
} for (stack_v, stack_childIndex) in p.stack],
}
# TODO : (MAYBE) Convert all those booleans into an integer 'status' Flags
# TODO : Convert all those booleans into an 8 bit integer 'status' flag
if bool(p.b):
w_ap['hasBody'] = True
if p.hasChildren():
Expand Down Expand Up @@ -1435,6 +1431,7 @@ wsPort = 32125
w_states["canUndo"] = self.commander.canUndo()
w_states["canRedo"] = self.commander.canRedo()
w_states["canDemote"] = self.commander.canDemote()
w_states["canPromote"] = self.commander.canPromote()
w_states["canDehoist"] = self.commander.canDehoist()

except Exception as e:
Expand All @@ -1446,6 +1443,7 @@ wsPort = 32125
w_states["canUndo"] = False
w_states["canRedo"] = False
w_states["canDemote"] = False
w_states["canPromote"] = False
w_states["canDehoist"] = False

return self.sendLeoBridgePackage("states", w_states)
Expand Down
4 changes: 3 additions & 1 deletion leobridgeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ def getStates(self, p_package):
w_states["canUndo"] = self.commander.canUndo()
w_states["canRedo"] = self.commander.canRedo()
w_states["canDemote"] = self.commander.canDemote()
w_states["canPromote"] = self.commander.canPromote()
w_states["canDehoist"] = self.commander.canDehoist()

except Exception as e:
Expand All @@ -673,6 +674,7 @@ def getStates(self, p_package):
w_states["canUndo"] = False
w_states["canRedo"] = False
w_states["canDemote"] = False
w_states["canPromote"] = False
w_states["canDehoist"] = False

return self.sendLeoBridgePackage("states", w_states)
Expand Down Expand Up @@ -1204,7 +1206,7 @@ def p_to_ap(self, p):
'headline': stack_v.h,
} for (stack_v, stack_childIndex) in p.stack],
}
# TODO : (MAYBE) Convert all those booleans into an integer 'status' Flags
# TODO : Convert all those booleans into an 8 bit integer 'status' flag
if bool(p.b):
w_ap['hasBody'] = True
if p.hasChildren():
Expand Down
69 changes: 41 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,12 @@
"title": "Goto Next Clone"
},
{
"command": "leointeg.gotoNextCloneFromOutline",
"command": "leointeg.gotoNextCloneSelection",
"category": "Leo",
"title": "Goto Next Clone"
},
{
"command": "leointeg.gotoNextCloneSelectionFromOutline",
"category": "Leo",
"title": "Goto Next Clone"
},
Expand Down Expand Up @@ -1019,11 +1024,11 @@
},
{
"command": "leointeg.markSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && !leoMarked"
},
{
"command": "leointeg.unmarkSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && leoMarked"
},
{
"command": "leointeg.copyNodeSelection",
Expand Down Expand Up @@ -1071,15 +1076,15 @@
},
{
"command": "leointeg.promoteSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && leoCanPromote"
},
{
"command": "leointeg.demoteSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && leoCanDemote"
},
{
"command": "leointeg.sortChildrenSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && leoChild"
},
{
"command": "leointeg.sortSiblingsSelection",
Expand All @@ -1091,7 +1096,7 @@
},
{
"command": "leointeg.refreshFromDiskSelection",
"when": "leoTreeOpened"
"when": "leoTreeOpened && leoAtFile"
},
{
"command": "leointeg.undo",
Expand Down Expand Up @@ -1146,8 +1151,8 @@
"when": "leoTreeOpened"
},
{
"command": "leointeg.gotoNextClone",
"when": "leoTreeOpened"
"command": "leointeg.gotoNextCloneSelection",
"when": "leoTreeOpened && leoCloned"
},
{
"command": "leointeg.markChangedItems",
Expand Down Expand Up @@ -1213,6 +1218,14 @@
"command": "leointeg.contractAllFromOutline",
"when": "false"
},
{
"command": "leointeg.gotoNextClone",
"when": "false"
},
{
"command": "leointeg.gotoNextCloneSelectionFromOutline",
"when": "false"
},
{
"command": "leointeg.editHeadline",
"when": "false"
Expand Down Expand Up @@ -1346,7 +1359,7 @@
"when": "false"
},
{
"command": "leointeg.gotoNextCloneFromOutline",
"command": "leointeg.gotoNextCloneSelectionFromOutline",
"when": "false"
},
{
Expand Down Expand Up @@ -1525,7 +1538,12 @@
},
{
"command": "leointeg.hoistNode",
"when": "viewItem =~ /leoNode/",
"when": "viewItem =~ /leoNodeNotRoot/",
"group": "leoNodeContext1@2"
},
{
"command": "leointeg.dehoist",
"when": "leoCanDehoist && viewItem =~ /leoNodeRoot/",
"group": "leoNodeContext1@2"
},
{
Expand Down Expand Up @@ -1579,14 +1597,9 @@
"group": "leoNodeContext3@2"
},
{
"command": "leointeg.promote",
"when": "leoTreeOpened && viewItem =~ /leoNode/",
"command": "leointeg.gotoNextClone",
"when": "leoTreeOpened && viewItem =~ /leoNodeCloned/",
"group": "leoNodeContext3@3"
},
{
"command": "leointeg.demote",
"when": "leoTreeOpened && viewItem =~ /leoNode/",
"group": "leoNodeContext3@4"
}
]
},
Expand All @@ -1602,12 +1615,12 @@
"when": "leoTreeOpened && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.gotoNextCloneFromOutline",
"command": "leointeg.gotoNextCloneSelectionFromOutline",
"key": "alt+n",
"when": "leoTreeOpened && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.gotoNextClone",
"command": "leointeg.gotoNextCloneSelection",
"key": "alt+n",
"when": "leoTreeOpened && editorTextFocus && resourceScheme == leo"
},
Expand Down Expand Up @@ -1746,57 +1759,57 @@
"command": "leointeg.markSelection",
"key": "ctrl+m",
"mac": "cmd+m",
"when": "leoTreeOpened && !leoNodeMarked && editorTextFocus && resourceScheme == leo"
"when": "leoTreeOpened && !leoMarked && editorTextFocus && resourceScheme == leo"
},
{
"command": "leointeg.markSelectionFromOutline",
"key": "ctrl+m",
"mac": "cmd+m",
"when": "leoTreeOpened && !leoNodeMarked && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
"when": "leoTreeOpened && !leoMarked && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.unmarkSelection",
"key": "ctrl+m",
"mac": "cmd+m",
"when": "leoTreeOpened && leoNodeMarked && editorTextFocus && resourceScheme == leo"
"when": "leoTreeOpened && leoMarked && editorTextFocus && resourceScheme == leo"
},
{
"command": "leointeg.unmarkSelectionFromOutline",
"key": "ctrl+m",
"mac": "cmd+m",
"when": "leoTreeOpened && leoNodeMarked && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
"when": "leoTreeOpened && leoMarked && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.promoteSelection",
"key": "ctrl+[BracketLeft]",
"win": "ctrl+oem_4",
"linux": "ctrl+[",
"mac": "cmd+[BracketLeft]",
"when": "leoTreeOpened && editorTextFocus && resourceScheme == leo"
"when": "leoTreeOpened && leoCanPromote && editorTextFocus && resourceScheme == leo"
},
{
"command": "leointeg.promoteSelectionFromOutline",
"key": "ctrl+[BracketLeft]",
"win": "ctrl+oem_4",
"linux": "ctrl+[",
"mac": "cmd+[BracketLeft]",
"when": "leoTreeOpened && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
"when": "leoTreeOpened && leoCanPromote && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.demoteSelection",
"key": "ctrl+[BracketRight]",
"win": "ctrl+oem_6",
"linux": "ctrl+]",
"mac": "cmd+[BracketRight]",
"when": "leoTreeOpened && editorTextFocus && resourceScheme == leo"
"when": "leoTreeOpened && leoCanDemote && editorTextFocus && resourceScheme == leo"
},
{
"command": "leointeg.demoteSelectionFromOutline",
"key": "ctrl+[BracketRight]",
"win": "ctrl+oem_6",
"linux": "ctrl+]",
"mac": "cmd+[BracketRight]",
"when": "leoTreeOpened && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
"when": "leoTreeOpened && leoCanDemote && sideBarFocus && focusedView =~ /leoIntegration|leoDocuments/"
},
{
"command": "leointeg.moveOutlineDownSelection",
Expand Down
25 changes: 19 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,24 @@ export class Constants {
LEO_CAN_UNDO: "leoCanUndo",
LEO_CAN_REDO: "leoCanRedo",
LEO_CAN_DEMOTE: "leoCanDemote",
LEO_CAN_PROMOTE: "leoCanPromote",
LEO_CAN_DEHOIST: "leoCanDehoist",
// Flags for current selection in outline tree view
// 'states' flags about current selection, for visibility and commands availability
SELECTED_MARKED: "leoMarked", // no need for unmarked here, use !leoMarked
SELECTED_CLONE: "leoCloned",
SELECTED_DIRTY: "leoDirty",
SELECTED_EMPTY: "leoEmpty",
SELECTED_CHILD: "leoChild", // Has children
SELECTED_ATFILE: "LeoAtFile", // Can be refreshed
// Statusbar Flag 'keybindings in effect'
LEO_SELECTED: "leoObjectSelected", // keybindings "On": Outline or body has focus
SELECTED_MARKED: "leoNodeMarked", // Selected node is marked
SELECTED_UNMARKED: "leoNodeUnmarked", // Selected node is unmarked
SELECTED_ATFILE: "leoNodeAtFile", // Selected node is an @file or @clean, etc...
// Context Flags for 'when' clauses, used concatenated, for each outline node
NODE_MARKED: "leoNodeMarked", // Selected node is marked
NODE_UNMARKED: "leoNodeUnmarked", // Selected node is unmarked (Needed for regexp)
NODE_ATFILE: "leoNodeAtFile", // Selected node is an @file or @clean, etc...
NODE_CLONED: "leoNodeCloned",
NODE_ROOT: "leoNodeRoot",
NODE_NOT_ROOT: "leoNodeNotRoot",
// Flags for Leo documents tree view icons and hover node command buttons
DOCUMENT_SELECTED_TITLED: "leoDocumentSelectedTitled",
DOCUMENT_TITLED: "leoDocumentTitled",
Expand All @@ -177,7 +189,7 @@ export class Constants {
LEO_TREE_BROWSE: Constants.CONFIG.LEO_TREE_BROWSE, // Leo outline also in the explorer view
TREE_IN_EXPLORER: Constants.CONFIG.TREE_IN_EXPLORER, // Leo outline also in the explorer view
SHOW_OPEN_ASIDE: Constants.CONFIG.SHOW_OPEN_ASIDE, // Show 'open aside' in context menu
SHOW_EDIT: Constants.CONFIG.SHOW_EDIT, // Hover Icons on outline nodes
SHOW_EDIT: Constants.CONFIG.SHOW_EDIT, // Hover Icons on outline nodes
SHOW_ARROWS: Constants.CONFIG.SHOW_ARROWS, // Hover Icons on outline nodes
SHOW_ADD: Constants.CONFIG.SHOW_ADD, // Hover Icons on outline nodes
SHOW_MARK: Constants.CONFIG.SHOW_MARK, // Hover Icons on outline nodes
Expand Down Expand Up @@ -331,7 +343,8 @@ export class Constants {
GOTO_PREV_VISIBLE: "gotoPrevVisible",
GOTO_NEXT_MARKED: "gotoNextMarked",
GOTO_NEXT_CLONE: "gotoNextClone",
GOTO_NEXT_CLONE_FO: "gotoNextCloneFromOutline",
GOTO_NEXT_CLONE_SELECTION: "gotoNextCloneSelection",
GOTO_NEXT_CLONE_SELECTION_FO: "gotoNextCloneSelectionFromOutline",
CONTRACT_OR_GO_LEFT: "contractOrGoLeft",
EXPAND_AND_GO_RIGHT: "expandAndGoRight",
// * Leo Operations
Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export function activate(p_context: vscode.ExtensionContext) {
[w_cmdPrefix + Constants.COMMANDS.GOTO_FIRST_VISIBLE, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_FIRST_VISIBLE, undefined, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_LAST_VISIBLE, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_LAST_VISIBLE, undefined, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_LAST_SIBLING, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_LAST_SIBLING, undefined, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_CLONE, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_CLONE, undefined, RefreshType.RefreshTreeAndBody, false)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_CLONE_FO, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_CLONE, undefined, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_CLONE, (p_node: LeoNode) => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_CLONE, p_node, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_CLONE_SELECTION, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_CLONE, undefined, RefreshType.RefreshTreeAndBody, false)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_CLONE_SELECTION_FO, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_CLONE, undefined, RefreshType.RefreshTreeAndBody, true)],

[w_cmdPrefix + Constants.COMMANDS.GOTO_NEXT_VISIBLE, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_NEXT_VISIBLE, undefined, RefreshType.RefreshTreeAndBody, true)],
[w_cmdPrefix + Constants.COMMANDS.GOTO_PREV_VISIBLE, () => w_leoIntegration.nodeCommand(Constants.LEOBRIDGE.GOTO_PREV_VISIBLE, undefined, RefreshType.RefreshTreeAndBody, true)],
Expand Down
4 changes: 2 additions & 2 deletions src/leoBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {

public stat(p_uri: vscode.Uri): vscode.FileStat | Thenable<vscode.FileStat> {
// TODO : Fix extraneous stat(...) call(s)
if (this._leoIntegration.fileOpenedReady) {
if (this._leoIntegration.leoStates.fileOpenedReady) {
if (p_uri.fsPath.length === 1) { // p_uri.fsPath === '/' || p_uri.fsPath === '\\'
// console.log('called stat on root');
return { type: vscode.FileType.Directory, ctime: 0, mtime: 0, size: 0 };
Expand Down Expand Up @@ -175,7 +175,7 @@ export class LeoBodyProvider implements vscode.FileSystemProvider {
}

public readFile(p_uri: vscode.Uri): Thenable<Uint8Array> {
if (this._leoIntegration.fileOpenedReady) {
if (this._leoIntegration.leoStates.fileOpenedReady) {
if (p_uri.fsPath.length === 1) { // p_uri.fsPath === '/' || p_uri.fsPath === '\\'
throw vscode.FileSystemError.FileIsADirectory();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/leoBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class LeoBridge {
console.log(`Websocket closed, code: ${p_event.code}`);
this._rejectAction(`Websocket closed, code: ${p_event.code}`);
// TODO : Implement a better connection error handling
if (this._leoIntegration.leoBridgeReady) {
if (this._leoIntegration.leoStates.leoBridgeReady) {
this._leoIntegration.cancelConnect(`Websocket closed, code: ${p_event.code}`);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/leoDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class LeoDocumentsProvider implements vscode.TreeDataProvider<LeoDocument
public getChildren(element?: LeoDocumentNode): Thenable<LeoDocumentNode[]> {

// if called with element, or not ready, give back empty array as there won't be any children
if (this._leoIntegration.fileOpenedReady && !element) {
if (this._leoIntegration.leoStates.fileOpenedReady && !element) {

// call action to get get list, and convert to LeoDocumentNode(s) array
return this._leoIntegration.sendAction(Constants.LEOBRIDGE.GET_OPENED_FILES).then(p_package => {
Expand Down
Loading

0 comments on commit 418acb6

Please sign in to comment.