summaryrefslogtreecommitdiff
path: root/grc/gui/ActionHandler.py
diff options
context:
space:
mode:
authorKartik Patel <kartikpatel1995@gmail.com>2017-01-26 02:34:44 +0530
committerKartik Patel <kartikpatel1995@gmail.com>2017-01-26 22:42:46 +0530
commit6dca1fb5af51fe508ce5e4ad7872cf468654c6bb (patch)
tree3bb7a0c72923d9dbe2a4f19382d2d9903a6bd07c /grc/gui/ActionHandler.py
parentb75e16ff8b20957512b660640eb6567c0395b89d (diff)
grc: 'Save a copy' feature added
Diffstat (limited to 'grc/gui/ActionHandler.py')
-rw-r--r--grc/gui/ActionHandler.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index cab484d04d..dc5f3e287d 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -30,6 +30,7 @@ from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
from .MainWindow import MainWindow
from .ParserErrorsDialog import ParserErrorsDialog
from .PropsDialog import PropsDialog
+
from ..core import ParseXML, Messages
gobject.threads_init()
@@ -129,7 +130,8 @@ class ActionHandler:
action.set_sensitive(False) # set all actions disabled
for action in (
Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW,
- Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, Actions.FLOW_GRAPH_DUPLICATE,
+ Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS,
+ Actions.FLOW_GRAPH_DUPLICATE, Actions.FLOW_GRAPH_SAVE_A_COPY,
Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY,
Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY,
Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW,
@@ -560,6 +562,22 @@ class ActionHandler:
Preferences.add_recent_file(file_path)
main.tool_bar.refresh_submenus()
main.menu_bar.refresh_submenus()
+ elif action == Actions.FLOW_GRAPH_SAVE_A_COPY:
+ try:
+ if not page.get_file_path():
+ Actions.FLOW_GRAPH_SAVE_AS()
+ else:
+ dup_file_path = page.get_file_path()
+ dup_file_name = '.'.join(dup_file_path.split('.')[:-1]) + "_copy" # Assuming .grc extension at the end of file_path
+ dup_file_path_temp = dup_file_name+'.grc'
+ count = 1
+ while (os.path.exists(dup_file_path_temp)):
+ dup_file_path_temp = dup_file_name+'('+str(count)+').grc'
+ count += 1
+ ParseXML.to_file(flow_graph.export_data(), dup_file_path_temp)
+ Messages.send("Successfully copied to " + dup_file_path_temp)
+ except IOError:
+ Messages.send_fail_save("Can not create a copy of the flowgraph")
elif action == Actions.FLOW_GRAPH_DUPLICATE:
curr_flow_graph = main.get_flow_graph()
main.new_page(flow_graph = curr_flow_graph)