@ -79,7 +79,14 @@ public class VcsHelper implements JTemplateActionListener {
EventDispatcher . listen ( ConfigEvent . READY , new ListenerAdaptor ( ) {
EventDispatcher . listen ( ConfigEvent . READY , new ListenerAdaptor ( ) {
@Override
@Override
protected void on ( Event event ) {
protected void on ( Event event ) {
legacyMode = WorkContext . getCurrent ( ) . get ( VcsOperator . class ) . isLegacyMode ( ) ;
try {
legacyMode = WorkContext . getCurrent ( ) . get ( VcsOperator . class ) . isLegacyMode ( ) ;
FineLoggerFactory . getLogger ( ) . info ( "[VcsHelper] legacyMode:{}" , legacyMode ) ;
} catch ( Exception e ) {
//保险起见走老逻辑
legacyMode = true ;
FineLoggerFactory . getLogger ( ) . error ( "[VcsHelper] get legacy failed" , e . getMessage ( ) ) ;
}
}
}
} ) ;
} ) ;
}
}
@ -99,7 +106,6 @@ public class VcsHelper implements JTemplateActionListener {
JTemplate template = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
JTemplate template = HistoryTemplateListCache . getInstance ( ) . getCurrentEditingTemplate ( ) ;
if ( DesignerEnvManager . getEnvManager ( ) . getVcsConfigManager ( ) . isVcsEnable ( ) & & JTemplate . isValid ( template ) ) {
if ( DesignerEnvManager . getEnvManager ( ) . getVcsConfigManager ( ) . isVcsEnable ( ) & & JTemplate . isValid ( template ) ) {
fireAutoSaveVcs ( template ) ;
fireAutoSaveVcs ( template ) ;
FineLoggerFactory . getLogger ( ) . info ( "[VcsV2] fire Vcs auto save success!" ) ;
}
}
}
}
} , interval , interval , TimeUnit . MINUTES ) ;
} , interval , interval , TimeUnit . MINUTES ) ;
@ -263,7 +269,7 @@ public class VcsHelper implements JTemplateActionListener {
@Override
@Override
public void templateOpened ( JTemplate < ? , ? > jt ) {
public void templateOpened ( JTemplate < ? , ? > jt ) {
try {
try {
if ( VcsConfigManager . getInstance ( ) . isUseAutoSave ( ) ) {
if ( checkAutoSaveSupport ( ) ) {
startAutoSave ( VcsConfigManager . getInstance ( ) . getAutoSaveInterval ( ) ) ;
startAutoSave ( VcsConfigManager . getInstance ( ) . getAutoSaveInterval ( ) ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
@ -282,25 +288,16 @@ public class VcsHelper implements JTemplateActionListener {
* @param jt 模板
* @param jt 模板
* /
* /
public void fireAutoSaveVcs ( final JTemplate jt ) {
public void fireAutoSaveVcs ( final JTemplate jt ) {
ExecutorService fireVcs = Executors . newSingleThreadExecutor ( new NamedThreadFactory ( "autoFireVcs" ) ) ;
String fileName = getEditingFilename ( ) ;
fireVcs . execute ( new Runnable ( ) {
VcsOperator operator = WorkContext . getCurrent ( ) . get ( VcsOperator . class ) ;
@Override
VcsEntity entity = operator . getFileVersionByIndex ( fileName , 0 ) ;
public void run ( ) {
boolean replace = needDeleteVersion ( entity ) ;
String fileName = getEditingFilename ( ) ;
int latestFileVersion = 0 ;
VcsOperator operator = WorkContext . getCurrent ( ) . get ( VcsOperator . class ) ;
if ( entity ! = null ) {
VcsEntity entity = operator . getFileVersionByIndex ( fileName , 0 ) ;
latestFileVersion = entity . getVersion ( ) ;
boolean replace = needDeleteVersion ( entity ) ;
}
int latestFileVersion = 0 ;
if ( JTemplate . isValid ( jt ) ) {
if ( entity ! = null ) {
doSave ( jt , fileName , latestFileVersion , replace , operator ) ;
latestFileVersion = entity . getVersion ( ) ;
}
if ( JTemplate . isValid ( jt ) ) {
doSave ( jt , fileName , latestFileVersion , replace , operator ) ;
}
}
} ) ;
if ( ! fireVcs . isShutdown ( ) ) {
fireVcs . shutdown ( ) ;
}
}
}
}
@ -348,7 +345,9 @@ public class VcsHelper implements JTemplateActionListener {
@Override
@Override
public void templateClosed ( JTemplate < ? , ? > jt ) {
public void templateClosed ( JTemplate < ? , ? > jt ) {
try {
try {
stopAutoSave ( ) ;
if ( checkAutoSaveSupport ( ) ) {
stopAutoSave ( ) ;
}
} catch ( Exception e ) {
} catch ( Exception e ) {
FineLoggerFactory . getLogger ( ) . error ( e . getMessage ( ) ) ;
FineLoggerFactory . getLogger ( ) . error ( e . getMessage ( ) ) ;
}
}
@ -372,4 +371,13 @@ public class VcsHelper implements JTemplateActionListener {
public boolean checkMoveFunctionSupport ( ) {
public boolean checkMoveFunctionSupport ( ) {
return VcsHelper . getInstance ( ) . isLegacyMode ( ) & & ( WorkContext . getCurrent ( ) . isLocal ( ) | | WorkContext . getCurrent ( ) . isRoot ( ) ) ;
return VcsHelper . getInstance ( ) . isLegacyMode ( ) & & ( WorkContext . getCurrent ( ) . isLocal ( ) | | WorkContext . getCurrent ( ) . isRoot ( ) ) ;
}
}
/ * *
* 是否支持自动保存
*
* @return 支持返回true
* /
public boolean checkAutoSaveSupport ( ) {
return VcsConfigManager . getInstance ( ) . isUseAutoSave ( ) & & ! VcsHelper . getInstance ( ) . isLegacyMode ( ) ;
}
}
}