Skip to content

Commit

Permalink
reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
xulihang committed Dec 22, 2018
1 parent 9fddf8c commit dc16283
Show file tree
Hide file tree
Showing 2 changed files with 296 additions and 312 deletions.
115 changes: 62 additions & 53 deletions BasicCAT/BasicCAT.b4j
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,59 @@ Sub newProject(sourceLang As String,targetLang As String)
Utils.enableMenuItems(MenuBar1,Array As String("_Save","_Close"))
End Sub


Sub openProject(path As String)
currentProject.Initialize
currentProject.open(path)
autosaveTimer.Enabled=True
MainForm.Title=getProjectname(path)
Utils.enableMenuItems(MenuBar1,Array As String("_Save","_Close"))
Utils.enableMenuItems(MenuBar1,File.ReadList(File.DirAssets,"menuText.txt"))
End Sub

Public Sub closeProject
autosaveTimer.Enabled=False
If currentProject.IsInitialized Then
If currentProject.projectTM.IsInitialized Then
currentProject.projectTM.close
End If
Dim currentProject As Project
tmTableView.ClearSelection
tmTableView.Items.Clear
projectTreeTableView.ClearSelection
projectTreeTableView.Root.Children.Clear
editorLV.Items.Clear
termLV.Items.Clear
MainForm.Title="BasicCAT"
Utils.disableMenuItems(MenuBar1,Array As String("_Save","_Close"))
Utils.disableMenuItems(MenuBar1,File.ReadList(File.DirAssets,"menuText.txt"))
End If
End Sub



Sub fillWithTM
If tmTableView.Items.Size<>0 Then
Log(tmTableView.SelectedRow)
If tmTableView.SelectedRow=-1 Then
tmTableView.SelectedRow=0
End If
If tmTableView.SelectedRowValues<>Null And editorLV.Items.Size<>0 Then
Try
Dim pane As Pane
pane=editorLV.Items.Get(currentProject.lastEntry)
Catch
Log(LastException)
Return
End Try
Dim targetTextArea As TextArea
targetTextArea=pane.GetNode(1)
targetTextArea.Text=tmTableView.SelectedRowValues(2)
currentProject.contentIsChanged
End If
End If
End Sub

Sub fillWithTheNextTag
If editorLV.Items.Size=0 Then
Return
Expand Down Expand Up @@ -1111,6 +1164,12 @@ Public Sub getProjectname(path As String) As String
Return Projectname
End Sub

'menu actions end
'-----------------------------

'editor relevant
'-----------------------------

Sub ListViewParent_Resize

Dim lv As ListView
Expand Down Expand Up @@ -1224,6 +1283,9 @@ Sub getVisibleRange(lv As ListView) As Range
Return visibleRange
End Sub

'other controls
'------------------------------

Sub searchTableView_MouseClicked (EventData As MouseEvent)
If EventData.PrimaryButtonPressed Then
If searchTableView.SelectedRowValues<>Null Then
Expand Down Expand Up @@ -1253,29 +1315,6 @@ Sub tmTableView_MouseClicked (EventData As MouseEvent)
End If
End Sub

Sub fillWithTM
If tmTableView.Items.Size<>0 Then
Log(tmTableView.SelectedRow)
If tmTableView.SelectedRow=-1 Then
tmTableView.SelectedRow=0
End If
If tmTableView.SelectedRowValues<>Null And editorLV.Items.Size<>0 Then
Try
Dim pane As Pane
pane=editorLV.Items.Get(currentProject.lastEntry)
Catch
Log(LastException)
Return
End Try
Dim targetTextArea As TextArea
targetTextArea=pane.GetNode(1)
targetTextArea.Text=tmTableView.SelectedRowValues(2)
currentProject.contentIsChanged
End If
End If

End Sub

Sub addTermButton_MouseClicked (EventData As MouseEvent)
If currentProject.IsInitialized Then
currentProject.projectTerm.addTerm(sourceTermTextField.Text,targetTermTextField1.Text)
Expand Down Expand Up @@ -1337,35 +1376,6 @@ Sub searchTableView_Action
End Select
End Sub

Sub openProject(path As String)
currentProject.Initialize
currentProject.open(path)
autosaveTimer.Enabled=True
MainForm.Title=getProjectname(path)
Utils.enableMenuItems(MenuBar1,Array As String("_Save","_Close"))
Utils.enableMenuItems(MenuBar1,File.ReadList(File.DirAssets,"menuText.txt"))
End Sub

Public Sub closeProject
autosaveTimer.Enabled=False
If currentProject.IsInitialized Then
If currentProject.projectTM.IsInitialized Then
currentProject.projectTM.close
End If
Dim currentProject As Project
tmTableView.ClearSelection
tmTableView.Items.Clear
projectTreeTableView.ClearSelection
projectTreeTableView.Root.Children.Clear
editorLV.Items.Clear
termLV.Items.Clear
MainForm.Title="BasicCAT"
Utils.disableMenuItems(MenuBar1,Array As String("_Save","_Close"))
Utils.disableMenuItems(MenuBar1,File.ReadList(File.DirAssets,"menuText.txt"))
End If
End Sub


Sub segmentSearchToggleButton_SelectedChange(Selected As Boolean)
'toggleTableOrTextArea(Selected,segmentSearchToggleButton,contextWebView,searchTableView)
toggleTableOrWebView(Selected,segmentSearchToggleButton,contextWebView,searchTableView)
Expand All @@ -1387,7 +1397,6 @@ Public Sub changeWhenSegmentOrSelectionChanges
End If
End Sub


Sub toggleTableOrWebView(selected As Boolean,tb As ToggleButton, wv As WebView,tv As TableView)
If selected Then
tb.Text="L"
Expand Down
Loading

0 comments on commit dc16283

Please sign in to comment.