private ToolStripItem FindItem(Tool tool) {
			for (int i = Items.Count - 1; i >= 0; --i) {
				if (Items[i].Tag == tool)
					return Items[i];
			}
			return null;
		}
		private ToolStripItem CreateItem(Tool tool) {
			ToolStripButton button = new ToolStripButton(null, tool.SmallIcon);
			button.Tag = tool;
			button.CheckOnClick = true;
			//button.Click += toolStripItem_Click;
			//button.DoubleClick += toolBoxStrip_DoubleClick;
			button.ToolTipText = tool.ToolTipText;
			button.DoubleClickEnabled = true;
			return button;
		}
Пример #3
0
		private void DoSelectTool(Tool tool, bool multiUse, bool ensureVisibility) {
			this.selectedTool = tool;
			this.executeOnce = !multiUse;

			if (diagramSetController != null)
				this.diagramSetController.ActiveTool = this.selectedTool;

			if (ToolSelected != null) {
				toolEventArgs.Tool = tool;
				ToolSelected(this, toolEventArgs);
			}
		}
Пример #4
0
		/// <ToBeCompleted></ToBeCompleted>
		public ToolEventArgs(Tool tool) {
			if (tool == null) throw new ArgumentNullException("tool");
			this.tool = tool;
		}
Пример #5
0
		/// <summary>
		/// Returns a collection of <see cref="T:Dataweb.NShape.Advanced.MenuItemDef" /> for constructing context menus etc.
		/// </summary>
		public IEnumerable<MenuItemDef> GetMenuItemDefs(Tool clickedTool) {
			// menu structure:
			//
			// Create Template...
			// Edit Template...
			// Delete Template
			// -------------------
			// Show Design Editor
			// Show Library manager

			bool isFeasible;
			string description;
			Template clickedTemplate = null;
			if (clickedTool is TemplateTool) clickedTemplate = ((TemplateTool)clickedTool).Template;

			isFeasible = true;
			description = "Create a new Template";
			yield return new DelegateMenuItemDef("Create Template...", null, description, isFeasible, Permission.Templates,
				(action, project) => OnTemplateEditorSelected(new TemplateEditorEventArgs(project)));

			isFeasible = (clickedTemplate != null);
			description = isFeasible ? string.Format("Edit Template '{0}'", clickedTemplate.Title) :
				"No template tool selected";
			yield return new DelegateMenuItemDef("Edit Template...", null, description, isFeasible, Permission.Templates,
				(action, project) => OnTemplateEditorSelected(new TemplateEditorEventArgs(project, clickedTemplate)));
			
			isFeasible =  (clickedTemplate != null);
			if (!isFeasible) 
				description = "No template tool selected";
			else {
				foreach (Template template in Project.Repository.GetTemplates()) {
					if (template.Shape.Template == clickedTemplate) {
						isFeasible = false;
						break;
					}
				}
				if (isFeasible) {
					// Check if template is in use
					foreach (Diagram diagram in Project.Repository.GetDiagrams()) {
						foreach (Shape shape in diagram.Shapes) {
							if (shape.Template == clickedTemplate) {
								isFeasible = false;
								break;
							}
						}
					}
				}
				if (isFeasible) description = string.Format("Delete Template '{0}'", clickedTemplate.Title);
				else description = string.Format("Template '{0}' is in use.", clickedTemplate.Title);
			}
			yield return new CommandMenuItemDef("Delete Template...", null, description, isFeasible,
				isFeasible ? new DeleteTemplateCommand(clickedTemplate) : null);

			yield return new SeparatorMenuItemDef();

			isFeasible = true;
			description = "Edit the current design or create new designs";
			yield return new DelegateMenuItemDef("Show Design Editor...", Properties.Resources.DesignEditorBtn,
				description, isFeasible, Permission.Designs,
				(action, project) => OnDesignEditorSelected(EventArgs.Empty));

			isFeasible = true;
			description = "Load and unload shape and/or model libraries";
			yield return new DelegateMenuItemDef("Show Library Manager...", Properties.Resources.LibrariesBtn,
				description, isFeasible, Permission.Templates,
				(action, project) => OnLibraryManagerSelected(EventArgs.Empty));
		}
Пример #6
0
		private void RefreshTool(Tool tool) {
			if (tool != null) {
				tool.RefreshIcons();
				if (tool != null && ToolChanged != null) {
					toolEventArgs.Tool = tool;
					ToolChanged(this, toolEventArgs);
				}
			}
		}
Пример #7
0
		/// <summary>
		///  Sets the given tool as the selected tool.
		/// </summary>
		public void SelectTool(Tool tool) {
			if (tool == null) throw new ArgumentNullException("tool");
			SelectTool(tool, false);
		}
Пример #8
0
		/// <summary>
		/// Selects the given tool.
		/// </summary>
		/// <param name="tool">Tool to select.</param>
		/// <param name="multiUse">If false, the default tool will be selected after executing the tool.</param>
		public void SelectTool(Tool tool, bool multiUse) {
			if (tool == null) throw new ArgumentNullException("tool");
			// If the tool to select equals the currently selected tool, skip tool selection
			if (tool != selectedTool) {
				// CurrentTool.Cancel would normally select the default tool.
				selecting = true;
				try {
					if (selectedTool != null)
						selectedTool.Cancel();
				} finally {
					selecting = false;
				}
				DoSelectTool(tool, multiUse, true);
			}
			executeOnce = !multiUse;
		}
Пример #9
0
		/// <summary>
		/// Adds a new tool to the toolbox.
		/// </summary>
		/// <param name="tool">CurrentTool to add</param>
		/// <param name="isDefaultTool">If true, this tool becomes the default tool.</param>
		public void AddTool(Tool tool, bool isDefaultTool) {
			if (tool == null) throw new ArgumentNullException("tool");
			tools.Add(tool);
			tool.ToolExecuted += Tool_ToolExecuted;
			if (tool is TemplateTool)
				((TemplateTool)tool).Template.Shape.DisplayService = this;
			tool.RefreshIcons();
			if (isDefaultTool) defaultTool = tool;
			//
			if (ToolAdded != null) {
				toolEventArgs.Tool = tool;
				ToolAdded(this, toolEventArgs);
			}
		}
Пример #10
0
		/// <summary>
		/// Deletes the given tool.
		/// </summary>
		public void DeleteTool(Tool tool) {
			if (tool == null) throw new ArgumentNullException("tool");
			if (tool == selectedTool) SelectDefaultTool(true);
			if (tool == defaultTool)
				if (tools.Count <= 0) defaultTool = null;
				else defaultTool = tools[0];
			tools.Remove(tool);
			if (ToolRemoved != null) {
				toolEventArgs.Tool = tool;
				ToolRemoved(this, toolEventArgs);
			}
			tool.Dispose();
		}
Пример #11
0
		/// <summary>
		/// Adds a new tool.
		/// </summary>
		/// <param name="tool"></param>
		public void AddTool(Tool tool) {
			if (tool == null) throw new ArgumentNullException("tool");
			AddTool(tool, tools.Count == 0);
		}
Пример #12
0
 private ListViewItem FindItem(Tool tool)
 {
     ListViewItem result = null;
     foreach (ListViewItem lvi in listView.Items)
         if (lvi.Tag == tool) {
             result = lvi;
             break;
         }
     return result;
 }
Пример #13
0
        private ListViewItem CreateItem(Tool tool)
        {
            ListViewItem item = new ListViewItem(tool.Title, tool.Name);
            item.ToolTipText = tool.ToolTipText;
            item.Tag = tool;

            int imgIdx = smallImageList.Images.IndexOfKey(tool.Name);
            if (imgIdx < 0) {
                smallImageList.Images.Add(tool.Name, tool.SmallIcon);
                largeImageList.Images.Add(tool.Name, tool.LargeIcon);
                imgIdx = smallImageList.Images.IndexOfKey(tool.Name);
            }
            item.ImageIndex = imgIdx;
            return item;
        }
Пример #14
0
		/// <ToBeCompleted></ToBeCompleted>
		public ToolExecutedEventArgs(Tool tool, ToolResult eventType)
			: base() {
			if (tool == null) throw new ArgumentNullException("tool");
			this.tool = tool;
			this.eventType = eventType;
		}
Пример #15
0
		private ToolStripButton FindToolStripButton(Tool tool) {
			ToolStripButton result = null;
			foreach (ToolStripItem tsi in toolBoxStrip.Items)
				if (tsi is ToolStripButton) {
					ToolStripButton tsb = (ToolStripButton)tsi;
					if (tsb.Tag == toolSetController.SelectedTool) {
						result = tsb;
					}
				}
			return result;
		}