summaryrefslogtreecommitdiff
path: root/grc
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
parentb75e16ff8b20957512b660640eb6567c0395b89d (diff)
grc: 'Save a copy' feature added
Diffstat (limited to 'grc')
-rw-r--r--grc/gui/ActionHandler.py20
-rw-r--r--grc/gui/Actions.py4
-rw-r--r--grc/gui/Bars.py1
3 files changed, 24 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)
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index a553c496ec..6eccab75fb 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -203,6 +203,10 @@ FLOW_GRAPH_SAVE_AS = Action(
stock_id=gtk.STOCK_SAVE_AS,
keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
)
+FLOW_GRAPH_SAVE_A_COPY = Action(
+ label='Save A Copy',
+ tooltip='Save the copy of current flowgraph',
+)
FLOW_GRAPH_DUPLICATE = Action(
label='_Duplicate',
tooltip='Create a duplicate of current flowgraph',
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index 2b182ea1fc..c17adf83a4 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -70,6 +70,7 @@ MENU_BAR_LIST = (
Actions.FLOW_GRAPH_SAVE,
Actions.FLOW_GRAPH_SAVE_AS,
Actions.FLOW_GRAPH_DUPLICATE,
+ Actions.FLOW_GRAPH_SAVE_A_COPY,
None,
Actions.FLOW_GRAPH_SCREEN_CAPTURE,
None,