Browse Source

Add ctrl-O and ctrl-shift-O to seek lines quickly

Leonardo Jeanteur 1 year ago
parent
commit
883186e03b
5 changed files with 68 additions and 10 deletions
  1. 2 0
      bin/defaultProps.json
  2. 4 0
      bin/style.css
  3. 5 0
      bin/style.less
  4. 54 9
      hide/comp/GlobalSeek.hx
  5. 3 1
      hide/comp/cdb/Editor.hx

+ 2 - 0
bin/defaultProps.json

@@ -66,6 +66,8 @@
 	"key.cdb.moveAhead" : "Alt-Right",
 
 	"key.cdb.globalSeek" : "Ctrl-P",
+	"key.cdb.sheetSeekIds" : "Ctrl-O",
+	"key.cdb.globalSeekIds" : "Ctrl-Shift-O",
 
 	// Scene editor config
 	"key.sceneeditor.focus": "F",

+ 4 - 0
bin/style.css

@@ -253,6 +253,10 @@ body .select2-container--default .select2-results__option--highlighted[aria-sele
   display: inline-block;
   margin: 0;
 }
+.hide-dropdown > .dropdown-cont .options .dropdown-option p.option-context {
+  margin-right: 5px;
+  color: #555;
+}
 .hide-dropdown > .dropdown-cont .options .dropdown-option.current-value {
   background-color: #444;
 }

+ 5 - 0
bin/style.less

@@ -260,6 +260,11 @@ body .select2-container--default {
 					margin: 0;
 				}
 
+				p.option-context {
+					margin-right: 5px;
+					color: #555;
+				}
+
 				&.current-value {
 					background-color: #444;
 				}

+ 54 - 9
hide/comp/GlobalSeek.hx

@@ -1,33 +1,78 @@
 package hide.comp;
+using hide.tools.Extensions;
+
+enum SeekMode {
+    Sheets;
+    LocalIds;
+    GlobalIds;
+}
 
 class GlobalSeek extends Modal {
     var cdbTable: hide.view.CdbTable;
 
     // Seeking files is not supported yet
-    public function new(?parent, cdbTable) {
+    public function new(?parent, cdbTable, mode: SeekMode, ?currentSheet: cdb.Sheet) {
         super(parent);
         this.cdbTable = cdbTable;
         element.addClass("global-seek");
 		var sheets = cdbTable.getSheets();
-        var choices : Array<hide.comp.Dropdown.Choice> = [
+        var choices : Array<hide.comp.Dropdown.Choice> = [];
+        if (mode == Sheets) {
             for( s in sheets ) {
-                id : s.name,
-                ico : null,
-                text : s.name,
+                choices.push({
+                    id : s.name,
+                    ico : null,
+                    text : s.name,
+                });
+            }
+        } else {
+            function addSheet(s: cdb.Sheet) {
+                for (i in 0...s.all.length) {
+                    var l = s.all[i];
+                    var id = Reflect.field(l, s.idCol.name);
+                    if (l.id != null) {
+                        choices.push({
+                            id: '#${s.name}:$id',
+                            ico: s.name,
+                            text: l.disp,
+                        });
+                    }
+                }
+            }
+            if (currentSheet != null && currentSheet.idCol != null) {
+                addSheet(currentSheet);
             }
-        ];
+            if (mode == GlobalIds) {
+                for( s in sheets ) {
+                    if (s.idCol != null && (currentSheet == null || currentSheet.name != s.name)) {
+                        addSheet(s);
+                    }
+                }
+            }
+        }
 
-        var d = new Dropdown(content, choices, null);
+        var d = new Dropdown(content, choices, null, function(c) {
+            if (c.ico == null)
+                return null;
+            return new Element('<p class="option-context">${c.ico}</p>');
+        });
 
         d.onSelect = function(val) {
             for( s in sheets ) {
                 if( s.name == val ) {
-                    cdbTable.goto(s);
+                    cdbTable.goto2(s, []);
                     return;
                 }
             }
+            if (StringTools.startsWith(val, "#") && currentSheet != null) {
+                var parts = val.substr(1).split(":");
+                var sname = parts[0];
+                var id = parts[1];
+                var s = sheets.find(s -> s.name == sname);
+                cdbTable.goto2(s, [Id(s.idCol.name, id)]);
+            }
         }
         d.onClose = close;
         modalClick = (_) -> close();
     }
-}
+}

+ 3 - 1
hide/comp/cdb/Editor.hx

@@ -158,7 +158,9 @@ class Editor extends Component {
 			}
 		});
 		keys.register("cdb.gotoReference", () -> gotoReference(cursor.getCell()));
-		keys.register("cdb.globalSeek", () -> new GlobalSeek(cdbTable.element, cdbTable));
+		keys.register("cdb.globalSeek", () -> new GlobalSeek(cdbTable.element, cdbTable, Sheets, currentSheet));
+		keys.register("cdb.sheetSeekIds", () -> new GlobalSeek(cdbTable.element, cdbTable, LocalIds, currentSheet));
+		keys.register("cdb.globalSeekIds", () -> new GlobalSeek(cdbTable.element, cdbTable, GlobalIds, currentSheet));
 
 		base = sheet.base;
 		if( cursor == null )