summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKartik Patel <kartikpatel1995@gmail.com>2017-01-25 16:03:25 +0530
committerKartik Patel <kartikpatel1995@gmail.com>2017-01-26 03:37:07 +0530
commitb75e16ff8b20957512b660640eb6567c0395b89d (patch)
tree23b8e418bf40e6dd144548f29a8b473984ccbc74
parent591369362b985ac721f1c7bd0ef4fea9b5c759d9 (diff)
grc: Add 'Create Duplicate' feature
-rw-r--r--grc/gui/ActionHandler.py6
-rw-r--r--grc/gui/Actions.py6
-rw-r--r--grc/gui/Bars.py1
-rw-r--r--grc/gui/MainWindow.py8
-rw-r--r--grc/gui/NotebookPage.py20
5 files changed, 30 insertions, 11 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index b9f534fdf0..cab484d04d 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -30,7 +30,6 @@ 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()
@@ -130,7 +129,7 @@ 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_OPEN, Actions.FLOW_GRAPH_SAVE_AS, Actions.FLOW_GRAPH_DUPLICATE,
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,
@@ -561,6 +560,9 @@ class ActionHandler:
Preferences.add_recent_file(file_path)
main.tool_bar.refresh_submenus()
main.menu_bar.refresh_submenus()
+ elif action == Actions.FLOW_GRAPH_DUPLICATE:
+ curr_flow_graph = main.get_flow_graph()
+ main.new_page(flow_graph = curr_flow_graph)
elif action == Actions.FLOW_GRAPH_SCREEN_CAPTURE:
file_path, background_transparent = SaveScreenShotDialog(page.get_file_path()).run()
if file_path is not None:
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index 9b2af36b93..a553c496ec 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -203,6 +203,12 @@ 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_DUPLICATE = Action(
+ label='_Duplicate',
+ tooltip='Create a duplicate of current flowgraph',
+ stock_id=gtk.STOCK_COPY,
+ keypresses=(gtk.keysyms.d, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
+)
FLOW_GRAPH_CLOSE = Action(
label='_Close',
tooltip='Close the current flow graph',
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index a4819b973c..2b182ea1fc 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -69,6 +69,7 @@ MENU_BAR_LIST = (
None,
Actions.FLOW_GRAPH_SAVE,
Actions.FLOW_GRAPH_SAVE_AS,
+ Actions.FLOW_GRAPH_DUPLICATE,
None,
Actions.FLOW_GRAPH_SCREEN_CAPTURE,
None,
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 686e73cfa3..50ba3839e2 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -247,7 +247,7 @@ class MainWindow(gtk.Window):
# Pages: create and close
############################################################
- def new_page(self, file_path='', show=False):
+ def new_page(self, file_path='', flow_graph = None, show=False):
"""
Create a new notebook page.
Set the tab to be selected.
@@ -263,13 +263,17 @@ class MainWindow(gtk.Window):
return
try: #try to load from file
if file_path: Messages.send_start_load(file_path)
- flow_graph = self._platform.get_new_flow_graph()
+ is_blank = False
+ if not flow_graph:
+ flow_graph = self._platform.get_new_flow_graph()
+ is_blank = True
flow_graph.grc_file_path = file_path
#print flow_graph
page = NotebookPage(
self,
flow_graph=flow_graph,
file_path=file_path,
+ is_blank = is_blank
)
if file_path: Messages.send_end_load()
except Exception, e: #return on failure
diff --git a/grc/gui/NotebookPage.py b/grc/gui/NotebookPage.py
index c9e8d0f186..417e7245ba 100644
--- a/grc/gui/NotebookPage.py
+++ b/grc/gui/NotebookPage.py
@@ -25,12 +25,12 @@ from StateCache import StateCache
from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
from DrawingArea import DrawingArea
import os
-
+from FlowGraph import FlowGraph
class NotebookPage(gtk.HBox):
"""A page in the notebook."""
- def __init__(self, main_window, flow_graph, file_path=''):
+ def __init__(self, main_window, flow_graph, file_path='', is_blank = True):
"""
Page constructor.
@@ -38,16 +38,22 @@ class NotebookPage(gtk.HBox):
main_window: main window
file_path: path to a flow graph file
"""
- self._flow_graph = flow_graph
+ self._flow_graph = FlowGraph(platform=flow_graph.platform)
self.process = None
#import the file
self.main_window = main_window
self.file_path = file_path
- initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
- self.state_cache = StateCache(initial_state)
- self.saved = True
#import the data to the flow graph
- self.get_flow_graph().import_data(initial_state)
+ if is_blank:
+ initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
+ self.state_cache = StateCache(initial_state)
+ self.get_flow_graph().import_data(initial_state)
+ self.saved = True
+ else:
+ initial_state = flow_graph.export_data()
+ self.state_cache = StateCache(initial_state)
+ self.get_flow_graph().import_data(initial_state)
+ self.saved = False
#initialize page gui
gtk.HBox.__init__(self, False, 0)
self.show()