Quellcode durchsuchen

:art: Attribute view support sticky layout https://github.com/siyuan-note/siyuan/pull/9617

Daniel vor 1 Jahr
Ursprung
Commit
a1ac6fb867
4 geänderte Dateien mit 39 neuen und 0 gelöschten Zeilen
  1. 2 0
      kernel/av/table.go
  2. 34 0
      kernel/model/attribute_view.go
  3. 2 0
      kernel/model/transaction.go
  4. 1 0
      kernel/treenode/node.go

+ 2 - 0
kernel/av/table.go

@@ -39,6 +39,7 @@ type ViewTableColumn struct {
 
 	Wrap   bool        `json:"wrap"`           // 是否换行
 	Hidden bool        `json:"hidden"`         // 是否隐藏
+	Pin    bool        `json:"pin"`            // 是否固定
 	Width  string      `json:"width"`          // 列宽度
 	Calc   *ColumnCalc `json:"calc,omitempty"` // 计算
 }
@@ -562,6 +563,7 @@ type TableColumn struct {
 	Icon   string      `json:"icon"`   // 列图标
 	Wrap   bool        `json:"wrap"`   // 是否换行
 	Hidden bool        `json:"hidden"` // 是否隐藏
+	Pin    bool        `json:"pin"`    // 是否固定
 	Width  string      `json:"width"`  // 列宽度
 	Calc   *ColumnCalc `json:"calc"`   // 计算
 

+ 34 - 0
kernel/model/attribute_view.go

@@ -366,6 +366,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
 			Wrap:         col.Wrap,
 			Hidden:       col.Hidden,
 			Width:        col.Width,
+			Pin:          col.Pin,
 			Calc:         col.Calc,
 		})
 	}
@@ -947,6 +948,39 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
 	return
 }
 
+func (tx *Transaction) doSetAttrViewColumnPin(operation *Operation) (ret *TxErr) {
+	err := setAttributeViewColPin(operation)
+	if nil != err {
+		return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
+	}
+	return
+}
+
+func setAttributeViewColPin(operation *Operation) (err error) {
+	attrView, err := av.ParseAttributeView(operation.AvID)
+	if nil != err {
+		return
+	}
+
+	view, err := attrView.GetView()
+	if nil != err {
+		return
+	}
+
+	switch view.LayoutType {
+	case av.LayoutTypeTable:
+		for _, column := range view.Table.Columns {
+			if column.ID == operation.ID {
+				column.Pin = operation.Data.(bool)
+				break
+			}
+		}
+	}
+
+	err = av.SaveAttributeView(attrView)
+	return
+}
+
 func (tx *Transaction) doSetAttrViewColumnIcon(operation *Operation) (ret *TxErr) {
 	err := setAttributeViewColIcon(operation)
 	if nil != err {

+ 2 - 0
kernel/model/transaction.go

@@ -208,6 +208,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
 			ret = tx.doSetAttrViewColumnWrap(op)
 		case "setAttrViewColHidden":
 			ret = tx.doSetAttrViewColumnHidden(op)
+		case "setAttrViewColPin":
+			ret = tx.doSetAttrViewColumnPin(op)
 		case "setAttrViewColIcon":
 			ret = tx.doSetAttrViewColumnIcon(op)
 		case "insertAttrViewBlock":

+ 1 - 0
kernel/treenode/node.go

@@ -582,6 +582,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
 			Wrap:         col.Wrap,
 			Hidden:       col.Hidden,
 			Width:        col.Width,
+			Pin:          col.Pin,
 			Calc:         col.Calc,
 		})
 	}