Skip to content

Commit

Permalink
- Added interface/command to test opened editor with file's timestamp…
Browse files Browse the repository at this point in the history
… and provide alert/notification

- New command hooked on tab active/clicked
- Command added to test when SVN, Git update/pull
(reference #633)
  • Loading branch information
Devsena committed Feb 3, 2020
1 parent fb8d1bb commit 7e4c76b
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package actionScripts.controllers

import actionScripts.events.AddTabEvent;
import actionScripts.events.EditorPluginEvent;
import actionScripts.events.FileChangeEvent;
import actionScripts.events.UpdateTabEvent;
import actionScripts.events.FilePluginEvent;
import actionScripts.events.GlobalEventDispatcher;
import actionScripts.events.OpenFileEvent;
Expand Down Expand Up @@ -230,7 +230,6 @@ package actionScripts.controllers
{
if (openAsTourDe) openTextFile(fileData, true);
else openTextFile(fileData);
GlobalEventDispatcher.getInstance().dispatchEvent(new FileChangeEvent(FileChangeEvent.EVENT_FILECHANGE,file.fileBridge.nativePath,0,0,0));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
////////////////////////////////////////////////////////////////////////////////
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
//
// No warranty of merchantability or fitness of any kind.
// Use this software at your own risk.
//
////////////////////////////////////////////////////////////////////////////////
package actionScripts.controllers
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;

import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.events.ResizeEvent;
import mx.managers.PopUpManager;

import spark.components.Button;

import actionScripts.events.GlobalEventDispatcher;
import actionScripts.locator.IDEModel;
import actionScripts.ui.IContentWindow;
import actionScripts.ui.IContentWindowReloadable;
import actionScripts.ui.editor.BasicTextEditor;
import actionScripts.ui.menu.MenuPlugin;
import actionScripts.ui.tabview.CloseTabEvent;
import actionScripts.valueObjects.ConstantsCoreVO;

import components.popup.StandardPopup;

public class UpdateTabCommand implements ICommand
{
private var model:IDEModel = IDEModel.getInstance();
private var dispatcher:GlobalEventDispatcher = GlobalEventDispatcher.getInstance();

private var tabToUpdate:IContentWindow;
private var pop:StandardPopup;

public function execute(event:Event):void
{
if (event.hasOwnProperty('tab'))
tabToUpdate = event['tab'];
else
tabToUpdate = model.activeEditor;

pop = new StandardPopup();
pop.data = this; // Keep the command from getting GC'd
pop.text = tabToUpdate.label + " is changed outside. Do you want to reload it?";

// Changed tabs are marked with * before the filename. Strip if found.
if (pop.text.charAt(0) == "*")
{
pop.text = pop.text.substr(1);
}

var save:Button = new Button();
save.styleName = "lightButton";
save.label = "Yes";
save.addEventListener(MouseEvent.CLICK, saveTab, false, 0, false);

var cancel:Button = new Button();
cancel.styleName = "lightButton";
cancel.label = "No";
cancel.addEventListener(MouseEvent.CLICK, seeFileAgain, false, 0, false);

pop.buttons = [save, cancel];

PopUpManager.addPopUp(pop, FlexGlobals.topLevelApplication as DisplayObject, true);
pop.y = (ConstantsCoreVO.IS_MACOS) ? 25 : 45;
pop.x = (FlexGlobals.topLevelApplication.width-pop.width)/2;

model.isIndividualCloseTabAlertShowing = true;

// @devsena
// we need this because if application frame resized when above alert
// opened, the alert didn't make it's position at center of the application but static
FlexGlobals.topLevelApplication.addEventListener(ResizeEvent.RESIZE, onApplicationResized);

// @devsena
// if quitCommand ask this to close, then close it
dispatcher.addEventListener(CloseTabEvent.EVENT_DISMISS_INDIVIDUAL_TAB_CLOSE_ALERT, onForceCloseRequest);
// disable file menus in OSX
dispatcher.dispatchEvent(new Event(MenuPlugin.CHANGE_MENU_MAC_NO_MENU_STATE));

}

private function cleanUp():void
{
if (pop)
{
FlexGlobals.topLevelApplication.removeEventListener(ResizeEvent.RESIZE, onApplicationResized);
dispatcher.removeEventListener(CloseTabEvent.EVENT_DISMISS_INDIVIDUAL_TAB_CLOSE_ALERT, onForceCloseRequest);
dispatcher.dispatchEvent(new Event(MenuPlugin.CHANGE_MENU_MAC_ENABLE_STATE));
PopUpManager.removePopUp(pop);
pop.data = null;
pop = null;
model.isIndividualCloseTabAlertShowing = false;
}

tabToUpdate = null;
}

private function onApplicationResized(event:ResizeEvent):void
{
if (pop) pop.x = (FlexGlobals.topLevelApplication.width-pop.width)/2;
}

private function onForceCloseRequest(event:Event):void
{
if (pop) cleanUp();
}

private function seeFileAgain(event:Event=null):void
{
if (tabToUpdate is BasicTextEditor)
{
model.mainView.mainContent.setSelectedTab(tabToUpdate as DisplayObject);
}
cleanUp();
}

private function saveTab(event:Event=null):void
{
if (tabToUpdate is IContentWindowReloadable)
{
(tabToUpdate as IContentWindowReloadable).reload();
}
cleanUp();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,20 @@
////////////////////////////////////////////////////////////////////////////////
package actionScripts.events
{
import actionScripts.factory.FileLocation;

import flash.events.Event;
import flash.display.DisplayObject;
import flash.events.Event;

public class FileChangeEvent extends Event
public class UpdateTabEvent extends Event
{
public static const EVENT_FILECHANGE:String = "newFileChangeEvent";
public static const EVENT_TAB_UPDATED_OUTSIDE:String = "tabUpdatedOutside";

public var filePath:String;
public var rootPath:String;
public var lineNumner:Number;
public var carPosition:Number;
public var version:Number;
public var tab:DisplayObject;



public function FileChangeEvent(type:String, filePath:String=null, lineNumner:Number = 0, carPosition:Number = 0,version:Number = 0 )
public function UpdateTabEvent(type:String, targetEditor:DisplayObject)
{
this.filePath = filePath;
//this.rootPath = rootPath;
this.lineNumner = lineNumner;
this.carPosition = carPosition;
this.version = version;
super(type, false, true);
this.tab = targetEditor;

super(type, false, false);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ package actionScripts.locator
import actionScripts.controllers.DeleteFileCommand;
import actionScripts.controllers.ICommand;
import actionScripts.controllers.OpenFileCommand;
import actionScripts.controllers.OpenLocationCommand;
import actionScripts.controllers.QuitCommand;
import actionScripts.controllers.RenameFileFolderCommand;
import actionScripts.controllers.SaveAsCommand;
import actionScripts.controllers.SaveFileCommand;
import actionScripts.controllers.UpdateTabCommand;
import actionScripts.events.AddTabEvent;
import actionScripts.events.DeleteFileEvent;
import actionScripts.events.GlobalEventDispatcher;
import actionScripts.events.OpenFileEvent;
import actionScripts.events.OpenLocationEvent;
import actionScripts.events.RenameFileFolderEvent;
import actionScripts.events.UpdateTabEvent;
import actionScripts.ui.menu.MenuPlugin;
import actionScripts.ui.tabview.CloseTabEvent;
import actionScripts.events.OpenLocationEvent;
import actionScripts.controllers.OpenLocationCommand;

public class IDEController
{
Expand All @@ -63,6 +65,7 @@ package actionScripts.locator
commands[OpenFileEvent.JUMP_TO_SEARCH_LINE] = OpenFileCommand;
commands[AddTabEvent.EVENT_ADD_TAB] = AddTabCommand;
commands[OpenLocationEvent.OPEN_LOCATION] = OpenLocationCommand;
commands[UpdateTabEvent.EVENT_TAB_UPDATED_OUTSIDE] = UpdateTabCommand;

commands[MenuPlugin.MENU_SAVE_AS_EVENT] = SaveAsCommand;
commands[MenuPlugin.MENU_SAVE_EVENT] = SaveFileCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
////////////////////////////////////////////////////////////////////////////////
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
//
// No warranty of merchantability or fitness of any kind.
// Use this software at your own risk.
//
////////////////////////////////////////////////////////////////////////////////
package actionScripts.ui
{
public interface IContentWindowReloadable
{
function reload():void;
function checkFileIfChanged():void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package actionScripts.ui.editor
import mx.events.FlexEvent;
import mx.managers.IFocusManagerComponent;
import mx.managers.PopUpManager;
import mx.utils.ObjectUtil;

import spark.components.Group;

Expand All @@ -33,11 +34,13 @@ package actionScripts.ui.editor
import actionScripts.events.GlobalEventDispatcher;
import actionScripts.events.RefreshTreeEvent;
import actionScripts.events.SaveFileEvent;
import actionScripts.events.UpdateTabEvent;
import actionScripts.factory.FileLocation;
import actionScripts.locator.IDEModel;
import actionScripts.plugin.actionscript.as3project.vo.AS3ProjectVO;
import actionScripts.plugin.console.ConsoleOutputEvent;
import actionScripts.ui.IContentWindow;
import actionScripts.ui.IContentWindowReloadable;
import actionScripts.ui.editor.text.DebugHighlightManager;
import actionScripts.ui.editor.text.TextEditor;
import actionScripts.ui.editor.text.vo.SearchResult;
Expand All @@ -47,39 +50,35 @@ package actionScripts.ui.editor

import components.popup.FileSavePopup;
import components.popup.SelectOpenedProject;
import components.views.project.TreeView;
import components.views.project.TreeView;

public class BasicTextEditor extends Group implements IContentWindow, IFocusManagerComponent
public class BasicTextEditor extends Group implements IContentWindow, IFocusManagerComponent, IContentWindowReloadable
{
public var defaultLabel:String = "New";
public var projectPath:String;
public var editor:TextEditor;
public var lastOpenType:String;

protected var lastOpenedUpdatedInMoonshine:Date;
protected var file:FileLocation;
protected var created:Boolean;
protected var loadingFile:Boolean;
protected var tempScrollTo:int = -1;
protected var loader: DataAgent;
protected var model:IDEModel = IDEModel.getInstance();
protected var dispatcher:GlobalEventDispatcher = GlobalEventDispatcher.getInstance();
protected var _isChanged:Boolean;

private var _readOnly:Boolean = false;
private var pop:FileSavePopup;
private var selectProjectPopup:SelectOpenedProject;
protected var isVisualEditor:Boolean;

private var _readOnly:Boolean = false;
public function get readOnly():Boolean
{
return this._readOnly;
}

private var pop:FileSavePopup;
protected var model:IDEModel = IDEModel.getInstance();

private var selectProjectPopup:SelectOpenedProject;

protected var isVisualEditor:Boolean;

protected var _isChanged:Boolean;

protected var dispatcher:GlobalEventDispatcher = GlobalEventDispatcher.getInstance();


public function get label():String
{
var labelChangeIndicator:String = _isChanged ? "*" : "";
Expand All @@ -90,7 +89,6 @@ package actionScripts.ui.editor

return labelChangeIndicator + file.fileBridge.name;
}

public function get longLabel():String
{
if (!file)
Expand All @@ -102,13 +100,11 @@ package actionScripts.ui.editor
{
return file;
}

public function set currentFile(value:FileLocation):void
{
if (file != value)
{
file = value;

dispatchEvent(new Event('labelChanged'));
}
}
Expand All @@ -117,7 +113,6 @@ package actionScripts.ui.editor
{
return editor.dataProvider;
}

public function set text(value:String):void
{
editor.dataProvider = value;
Expand Down Expand Up @@ -244,6 +239,7 @@ package actionScripts.ui.editor
{
loadingFile = true;
file = newFile;
lastOpenedUpdatedInMoonshine = file.fileBridge.modificationDate;
if (fileData)
{
openFileAsStringHandler(fileData as String);
Expand All @@ -257,6 +253,14 @@ package actionScripts.ui.editor
callLater(file.fileBridge.load);
}

public function checkFileIfChanged():void
{
if (ObjectUtil.dateCompare(file.fileBridge.modificationDate, lastOpenedUpdatedInMoonshine) != 0)
{
dispatcher.dispatchEvent(new UpdateTabEvent(UpdateTabEvent.EVENT_TAB_UPDATED_OUTSIDE, this));
}
}

public function reload():void
{
loadingFile = true;
Expand Down Expand Up @@ -426,6 +430,7 @@ package actionScripts.ui.editor
protected function updateChangeStatus():void
{
_isChanged = editor.hasChanged;
lastOpenedUpdatedInMoonshine = file.fileBridge.modificationDate;
dispatchEvent(new Event('labelChanged'));
}

Expand Down
Loading

0 comments on commit 7e4c76b

Please sign in to comment.