优化部分逻辑

This commit is contained in:
一二三 2024-06-17 23:41:57 +08:00
parent 6ac9cdfd6e
commit 947f767ac9
5 changed files with 1259 additions and 89 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<project ver="10" name="TabEditor++" libEmbed="true" icon="res\app.png" ui="win" output="TabEditor++.exe" CompanyName="单位名称" FileDescription="TabEditor++" LegalCopyright="Copyright (C) 作者 2024" ProductName="TabEditor++" InternalName="TabEditor++" FileVersion="0.0.0.4" ProductVersion="0.0.0.4" publishDir="/dist/" dstrip="false" local="false" ignored="false">
<project ver="10" name="TabEditor++" libEmbed="true" icon="res\app.ico" ui="win" output="TabEditor++.exe" CompanyName="" FileDescription="TabEditor++" LegalCopyright="Copyright (C) iioio.com 2024" ProductName="TabEditor++" InternalName="TabEditor++" FileVersion="0.0.0.7" ProductVersion="0.0.0.7" publishDir="/dist/" dstrip="true" local="false" ignored="false">
<file name="main.aardio" path="main.aardio" comment="main.aardio"/>
<folder name="资源文件" path="res" embed="true" local="false" ignored="false">
<file name="app.ico" path="res\app.ico" comment="res\app.ico"/>

View File

@ -5,19 +5,12 @@ winform.add(
btnSearchNext={cls="button";text="查找下一个(F)";left=218;top=83;right=306;bottom=113;db=1;dl=1;font=LOGFONT(name='微软雅黑');z=1};
btnSearchPrev={cls="button";text="查找下上个(V)";left=119;top=83;right=207;bottom=113;db=1;dl=1;font=LOGFONT(name='微软雅黑');z=2};
button={cls="button";text="关闭";left=327;top=82;right=386;bottom=112;db=1;dl=1;font=LOGFONT(name='微软雅黑');z=4};
checkbox={cls="checkbox";text="单元格匹配";left=16;top=86;right=108;bottom=113;bgcolor=16777215;checked=1;font=LOGFONT(h=-14);z=6};
editSearchInput={cls="combobox";left=81;top=28;right=392;bottom=54;db=1;dl=1;edge=1;font=LOGFONT(name='微软雅黑');items={};mode="dropdown";z=3};
static={cls="static";text="查找内容:";left=12;top=29;right=72;bottom=55;align="right";bgcolor=16777215;center=1;db=1;dl=1;font=LOGFONT(name='微软雅黑');transparent=1;z=5}
)
/*}}*/
winform.onCancel = function(){
winform.show(false);
}
winform.onOk = function(){
publish("search_next", winform.editSearchInput.text);
}
/*
窗口会自动检测默认的对话框快捷键,
默认Enter会触发onOk事件ESC键会触发onCancel事件
@ -39,9 +32,16 @@ winform.isDialogMessage = function(hwnd,msg){
return win.isDialogMessage(hwnd,msg);
}
winform.onClose = function(hwnd,message,wParam,lParam){
winform.onCancel = function(){
winform.show(false);
return false;//禁止关闭
}
pushSearchNext = function(){
publish("search_next", winform.editSearchInput.text, winform.checkbox.checked);
}
winform.onOk = function(){
pushSearchNext();
}
winform.btnSearchPrev.oncommand = function(id,event){
@ -49,7 +49,7 @@ winform.btnSearchPrev.oncommand = function(id,event){
}
winform.btnSearchNext.oncommand = function(id,event){
publish("search_next", winform.editSearchInput.text);
pushSearchNext();
}
winform.button.oncommand = function(id,event){
@ -60,6 +60,11 @@ winform.btnSearchPrev.disabled = true;
winform.editSearchInput.setFocus();
winform.onClose = function(hwnd,message,wParam,lParam){
winform.show(false);
return false;//禁止关闭
}
winform.show(false);
win.loopMessage();
return winform;

1151
lib/message.aardio Normal file

File diff suppressed because it is too large Load Diff

View File

@ -100,7 +100,6 @@ getTxtTableData = function(reference_row = 2){
}
col_count += 1;
}
break;
}
}
@ -111,7 +110,9 @@ getTxtTableData = function(reference_row = 2){
for i in ..string.lines(str,'\r\n','\t', col_count){
var col_values = {};
var isEmptyLine = false;
temp_cur_line += 1;
for (j=1; col_count; 1) {
if(#i == 0){
isEmptyLine = true;

View File

@ -1,7 +1,6 @@
//RUNAS
import win;
import win.ui;
import win.ui.mask;
import win.ui.toolbar;
import win.ui.accelerator;
import fonts.fontAwesome;
@ -33,15 +32,15 @@ var frmChild = mainForm.loadForm("\dlg\searchForm.aardio");
g_teMenus = teMenu.TeMenu(mainForm.plus);
//flexcell控件初始化
g_flexcell = flexcell.FlexGrid(mainForm.custom,,,1);
g_flexcell.setTheme(flexcell.FlexGrid.themeWps);
g_flexcell.isModified = false;
g_flexcell.ShowResizeTip = true;
teUtils.initFlexCellShow(g_flexcell);
g_flexcell.AllowFilter = false;
mainForm.g_flexcell = flexcell.FlexGrid(mainForm.custom,,,1);
mainForm.g_flexcell.setTheme(flexcell.FlexGrid.themeWps);
mainForm.g_flexcell.isModified = false;
mainForm.g_flexcell.ShowResizeTip = true;
teUtils.initFlexCellShow(mainForm.g_flexcell);
mainForm.g_flexcell.AllowFilter = false;
var showModifyStyle = function(){
g_flexcell.isModified = true;
mainForm.g_flexcell.isModified = true;
if(teUtils.getCurFilePath() == null){
g_teMenus.disabled(0, 3, true);
}
@ -54,7 +53,7 @@ var showModifyStyle = function(){
}
var showUnmodifyStyle = function(){
g_flexcell.isModified = false;
mainForm.g_flexcell.isModified = false;
g_teMenus.disabled(0, 3, true);
g_teMenus.disabled(0, 4, true);
mainForm.text = string.replace(mainForm.text, '[ ][\*]', "");
@ -65,16 +64,15 @@ showUnmodifyStyle();
//menu-新建
g_teMenus.newFile = function(ctrl){
return function(){
var curRow = g_flexcell.ActiveCell().Row;
var curCol = g_flexcell.ActiveCell().Col;
g_flexcell.FrozenRows = 0;
g_flexcell.FrozenCols = 0;
g_flexcell.range(0,0,0,g_flexcell.colCount).ClearBackColor();
g_flexcell.range(0,0,g_flexcell.rowCount,0).ClearBackColor();
g_flexcell.isModified = true;//避免 ModifyStyle, UnmodifyStyle 切换闪烁
g_flexcell.clear();
teUtils.initFlexCellShow(g_flexcell);
mainForm.release();
var curRow = mainForm.g_flexcell.ActiveCell().Row;
var curCol = mainForm.g_flexcell.ActiveCell().Col;
mainForm.g_flexcell.FrozenRows = 0;
mainForm.g_flexcell.FrozenCols = 0;
mainForm.g_flexcell.range(0,0,mainForm.g_flexcell.rowCount,mainForm.g_flexcell.colCount).ClearBackColor();
mainForm.g_flexcell.isModified = true;//避免 ModifyStyle, UnmodifyStyle 切换闪烁
mainForm.g_flexcell.clear();
teUtils.initFlexCellShow(mainForm.g_flexcell);
showUnmodifyStyle();
}
}
@ -82,31 +80,22 @@ g_teMenus.newFile = function(ctrl){
//menu-打开
g_teMenus.openFile = function(ctrl){
return function(){
var curRow = g_flexcell.ActiveCell().Row;
var curCol = g_flexcell.ActiveCell().Col;
g_flexcell.FrozenRows = 0;
g_flexcell.FrozenCols = 0;
g_flexcell.range(0,0,g_flexcell.rowCount,g_flexcell.colCount).ClearBackColor();
var frmMask = win.ui.mask(mainForm,true)
var t = teUtils.getTxtTableData();
frmMask.show(true);
win.delay(500);
if(t){
g_flexcell.AutoRedraw = false;
g_flexcell.setTable(t,,t.fields);
g_flexcell.column(0).AutoFit();
g_flexcell.AutoRedraw = true;
g_flexcell.Refresh();
g_teMenus.newFile();
mainForm.g_flexcell.AutoRedraw = false;
mainForm.g_flexcell.setTable(t,,t.fields);
mainForm.g_flexcell.column(0).AutoFit();
mainForm.g_flexcell.AutoRedraw = true;
mainForm.g_flexcell.Refresh();
}
frmMask.show(false);
showModifyStyle();
}
}
//menu-保存
g_teMenus.saveFile = function(ctrl){
return function(){
teUtils.saveTxtTableData(g_flexcell.getVlistData());
teUtils.saveTxtTableData(mainForm.g_flexcell.getVlistData());
showUnmodifyStyle();
}
}
@ -114,7 +103,7 @@ g_teMenus.saveFile = function(ctrl){
//menu-另存为
g_teMenus.saveAsFile = function(ctrl){
return function(){
teUtils.saveAsTxtTableData(g_flexcell.getVlistData());
teUtils.saveAsTxtTableData(mainForm.g_flexcell.getVlistData());
showUnmodifyStyle();
}
}
@ -122,7 +111,7 @@ g_teMenus.saveAsFile = function(ctrl){
//menu-设置背景色
g_teMenus.setBackground = function(ctrl){
return function(){
g_flexcell.selection().BackColor = color.rgbReverse(ctrl.backgroundColor);
mainForm.g_flexcell.selection().BackColor = color.rgbReverse(ctrl.backgroundColor);
}
}
import win.ui.ctrl.pick;
@ -155,7 +144,7 @@ g_teMenus.setBackgroundRClick = function(ctrl){
//menu-设置前景色
g_teMenus.setForeground = function(ctrl){
return function(){
g_flexcell.selection().ForeColor = color.rgbReverse(ctrl.argbColor);
mainForm.g_flexcell.selection().ForeColor = color.rgbReverse(ctrl.argbColor);
}
}
g_teMenus.setForegroundRClick = function(ctrl){
@ -192,29 +181,29 @@ var flexFreeeRow = FlexFreeeItem();
var setFlexFreee = function(freee){
if(flexFreeeCol.change){
g_flexcell.range(flexFreeeCol.start_row,
mainForm.g_flexcell.range(flexFreeeCol.start_row,
flexFreeeCol.start_col,
flexFreeeCol.end_row,
flexFreeeCol.end_col).setBorders(2/*_FlexCell2_Edge_Right*/, 0/*_FlexCell2_BorderStyle_cellFlat*/ );
}
if(flexFreeeRow.change){
g_flexcell.range(flexFreeeRow.start_row,
mainForm.g_flexcell.range(flexFreeeRow.start_row,
flexFreeeRow.start_col,
flexFreeeRow.end_row,
flexFreeeRow.end_col).setBorders(8/*_FlexCell2_Edge_Bottom*/ , 0/*_FlexCell2_BorderStyle_cellFlat*/ );
}
if(!freee){return true;}
g_flexcell.range(flexFreeeCol.start_row, flexFreeeCol.start_col, flexFreeeCol.end_row, flexFreeeCol.end_col
mainForm.g_flexcell.range(flexFreeeCol.start_row, flexFreeeCol.start_col, flexFreeeCol.end_row, flexFreeeCol.end_col
).setBorders(2/*_FlexCell2_Edge_Right*/, 1/*_FlexCell2_BorderStyle_cellFlat*/);
g_flexcell.range(flexFreeeRow.start_row, flexFreeeRow.start_col, flexFreeeRow.end_row, flexFreeeRow.end_col
mainForm.g_flexcell.range(flexFreeeRow.start_row, flexFreeeRow.start_col, flexFreeeRow.end_row, flexFreeeRow.end_col
).setBorders(8/*_FlexCell2_Edge_Bottom*/ , 1/*_FlexCell2_BorderStyle_cellFlat*/);;
}
//menu-冻结行&列
g_teMenus.freeeRowCol = function(ctrl){
return function(){
var curRow = g_flexcell.ActiveCell().Row;
var curCol = g_flexcell.ActiveCell().Col;
var curRow = mainForm.g_flexcell.ActiveCell().Row;
var curCol = mainForm.g_flexcell.ActiveCell().Col;
setFlexFreee(false);
@ -222,7 +211,7 @@ g_teMenus.freeeRowCol = function(ctrl){
flexFreeeCol.change = true;
flexFreeeCol.start_row = curRow+1;
flexFreeeCol.start_col = curCol;
flexFreeeCol.end_row = g_flexcell.rowCount;
flexFreeeCol.end_row = mainForm.g_flexcell.rowCount;
flexFreeeCol.end_col = curCol;
//绘制冻结行的底部边框线
@ -230,14 +219,14 @@ g_teMenus.freeeRowCol = function(ctrl){
flexFreeeRow.start_row = curRow;
flexFreeeRow.start_col = curCol+1;
flexFreeeRow.end_row = curRow;
flexFreeeRow.end_col = g_flexcell.colCount;
flexFreeeRow.end_col = mainForm.g_flexcell.colCount;
setFlexFreee(true);
//冻结行
g_flexcell.FrozenRows = curRow;
mainForm.g_flexcell.FrozenRows = curRow;
//冻结列
g_flexcell.FrozenCols = curCol;
mainForm.g_flexcell.FrozenCols = curCol;
}
}
@ -245,8 +234,8 @@ g_teMenus.freeeRowCol = function(ctrl){
g_teMenus.unfreeeRowCol = function(ctrl){
return function(){
setFlexFreee(false);
g_flexcell.FrozenRows = 0;
g_flexcell.FrozenCols = 0;
mainForm.g_flexcell.FrozenRows = 0;
mainForm.g_flexcell.FrozenCols = 0;
}
}
@ -265,7 +254,7 @@ g_teMenus.exportTxt = function(ctrl){
//menu-关于
g_teMenus.showAbout = function(ctrl){
return function(){
//g_flexcell.AboutBox();
//mainForm.g_flexcell.AboutBox();
}
}
@ -296,31 +285,33 @@ pre_searched_row = null;
pre_searched_col = null;
/*消息回调{{*/
g_flexcell.onCellChange = function(Row,Col){
if(!g_flexcell.isModified){
mainForm.g_flexcell.onCellChange = function(Row,Col){
if(!mainForm.g_flexcell.isModified){
showModifyStyle();
}
g_flexcell.isModified = true;
mainForm.g_flexcell.isModified = true;
}
g_flexcell.onClick = function(Row,Col){
mainForm.g_flexcell.onClick = function(Row,Col){
var row,col=owner.toRelativeRow(Row),owner.toRelativeCol(Col);
}
g_flexcell.onMouseUp = function(Button , Shift, x, y){
mainForm.g_flexcell.onMouseUp = function(Button , Shift, x, y){
/*** 鼠标按键放开。
Button 当前按下的鼠标按钮1左按钮2右按钮4中间按钮同时按下时执行位或操作。
Shift 功能键状态1SHIFT2CTRL4ALT同时按下时执行位或操作。
x,y 鼠标指针当前位置 ***/
if(Button == 2){
g_flexcell.cell(g_flexcell.MouseRow,g_flexcell.MouseCol).Select();
mainForm.g_flexcell.cell(mainForm.g_flexcell.MouseRow,mainForm.g_flexcell.MouseCol).Select();
}
if(pre_searched_row != null and pre_searched_col != null){
g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xffffff;
mainForm.g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xffffff;
pre_searched_row = null;
pre_searched_col = null;
}
}
g_flexcell.onSelChange = function(FirstRow,FirstCol,LastRow,LastCol){
mainForm.g_flexcell.onSelChange = function(FirstRow,FirstCol,LastRow,LastCol){
/*** 在Selection选择范围改变时发生。参数起始行起始列结束行结束列 ***/
var row1,col1=owner.toRelativeRow(FirstRow),owner.toRelativeCol(FirstCol);
var row2,col2=owner.toRelativeRow(LastRow),owner.toRelativeCol(LastCol);
@ -331,6 +322,7 @@ g_flexcell.onSelChange = function(FirstRow,FirstCol,LastRow,LastCol){
//搜索窗口
var openSearchForm = function(){
frmChild.show();
frmChild.editSearchInput.setFocus();
}
var accelerator = win.ui.accelerator({
@ -341,7 +333,7 @@ var accelerator = win.ui.accelerator({
},mainForm );
research_flag = true;
searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRangeSearch, selFirstRow, selFirstCol, str){
searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRangeSearch, selFirstRow, selFirstCol, searchContent, isCellMatching){
if(isRangeSearch){// 从一个范围开始搜索
//console.dump("从一个范围开始搜索");
var tempRow = firstRow;
@ -360,11 +352,21 @@ searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRange
if (i == pre_searched_row and i2 == pre_searched_col){
continue;
}
if(v[v2] == str){
research_flag = true;
pre_searched_row = i;
pre_searched_col = i2;
return i, i2;
if (isCellMatching){
if(v[v2] == searchContent){
research_flag = true;
pre_searched_row = i;
pre_searched_col = i2;
return i, i2;
}
}
else {
if(string.find(v[v2], searchContent)){
research_flag = true;
pre_searched_row = i;
pre_searched_col = i2;
return i, i2;
}
}
}
firstCol = tempRow;
@ -373,7 +375,7 @@ searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRange
// 搜不到了,重头搜索
if(research_flag){
research_flag = false;
row, col = searchNextContent(data, selFirstRow, selFirstCol, lastRow, lastCol, isRangeSearch, selFirstRow, selFirstCol, str);
row, col = searchNextContent(data, selFirstRow, selFirstCol, lastRow, lastCol, isRangeSearch, selFirstRow, selFirstCol, searchContent, isCellMatching);
return row, col;
}
research_flag = true;
@ -392,9 +394,17 @@ searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRange
if(i == firstRow and i2 == firstCol){
continue;
}
if(v[v2] == str){
research_flag = true;
return i, i2;
if (isCellMatching){
if(v[v2] == searchContent){
research_flag = true;
return i, i2;
}
}
else {
if(string.find(v[v2], searchContent)){
research_flag = true;
return i, i2;
}
}
}
firstCol = 1;
@ -403,7 +413,7 @@ searchNextContent = function(data, firstRow, firstCol, lastRow, lastCol, isRange
if(research_flag){
research_flag = false;
//console.dump("搜不到了,重头搜索");
row, col = searchNextContent(data, 1, 1, 1, 1, isRangeSearch, selFirstRow, selFirstCol, str);
row, col = searchNextContent(data, 1, 1, 1, 1, isRangeSearch, selFirstRow, selFirstCol, searchContent, isCellMatching);
return row, col;
}
research_flag = true;
@ -417,7 +427,10 @@ subscribe("search_prev",function(...){
subscribe("search_next",function(...){
var curSelection = g_flexcell.selection();
var args = {...};
var searchContent = args[1];
var isCellMatching = args[2];
var curSelection = mainForm.g_flexcell.selection();
var firstRow = curSelection.FirstRow;
var firstCol = curSelection.FirstCol;
var lastRow = curSelection.LastRow;
@ -427,21 +440,21 @@ subscribe("search_next",function(...){
isRangeSearch = true;
}
if(pre_searched_row != null and pre_searched_col != null){
g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xffffff;
mainForm.g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xffffff;
}
var row, col = searchNextContent(g_flexcell.getVlistData(), firstRow, firstCol, lastRow, lastCol, isRangeSearch, firstRow, firstCol, ...);
var row, col = searchNextContent(mainForm.g_flexcell.getVlistData(), firstRow, firstCol, lastRow, lastCol, isRangeSearch, firstRow, firstCol, searchContent, isCellMatching);
//console.dump(row, col);
if(row != null && col != null){
if(isRangeSearch){
if(pre_searched_row != null and pre_searched_col != null){
g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xff00ff;
mainForm.g_flexcell.Cell(pre_searched_row, pre_searched_col).BackColor = 0xff00ff;
}
g_flexcell.Cell(row, col).EnsureVisible();
mainForm.g_flexcell.Cell(row, col).EnsureVisible();
}
else {
pre_searched_row = null;
pre_searched_col = null;
g_flexcell.cell(row, col).Select();
mainForm.g_flexcell.cell(row, col).Select();
}
}
else {