Browse files

Issue #11 - Fixed selection of model and template in the dialog. Some…

… code refactoring. Removed registration of our own event that was used when dialog was shown using the context menu item.
  • Loading branch information...
1 parent 2c1d1d0 commit e48515ddc01f301df62db2f9233ab9d3fa4cb25c @sivanov-hill30 sivanov-hill30 committed Jan 31, 2012
View
6 NDjangoDesigner/Commands/AddViewCommand.cs
@@ -103,13 +103,13 @@ void IWizard.RunStarted(object automationObject, Dictionary<string, string> repl
// NOTE!
// 1 - Item in template XML must have its parameter ReplaceParameters being set to "true" in order for this to function!
// 2 - Strings to replace should end up with the line break
- if (viewDialog.SelectedModel != string.Empty)
+ if (viewDialog.IsViewModel)
replacementsDictionary.Add("$model$", "{% model Model:" + viewDialog.SelectedModel + " %}\r\n");
else
replacementsDictionary.Add("$model$", string.Empty);
- if (viewDialog.ModelToExtend != string.Empty)
- replacementsDictionary.Add("$extends$", "{% extends \"~\\" + viewDialog.ModelToExtend + "\" %}\r\n");
+ if (viewDialog.IsInheritance)
+ replacementsDictionary.Add("$extends$", "{% extends \"~\\" + viewDialog.TemplateToExtend + "\" %}\r\n");
else
replacementsDictionary.Add("$extends$", string.Empty);
View
90 NDjangoDesigner/Commands/AddViewDlg.cs
@@ -21,7 +21,7 @@ public partial class AddViewDlg : Form
public AddViewDlg()
{
InitializeComponent();
- this.MinimumSize = this.Size; // minimum size is set to what is defined in designer
+ MinimumSize = Size; // minimum size is set to what is defined in designer
WriteItemDirectly = true;
}
@@ -73,16 +73,25 @@ public bool ViewNameEnabled
public string SelectedModel
{
- get { return (comboModel.SelectedItem == null || comboModel.SelectedItem.ToString() == "None") ?
- string.Empty :
- comboBaseTemplate.SelectedItem.ToString(); }
+ get
+ {
+ string model = string.Empty;
+ if(IsViewModel)
+ model = comboModel.SelectedItem.ToString();
+ return model;
+ }
}
- public string ModelToExtend
+ public string TemplateToExtend
{
- get { return (comboModel.SelectedItem == null || comboModel.SelectedItem.ToString() == "None") ?
- string.Empty :
- comboModel.SelectedItem.ToString(); }
+ get
+ {
+ string template = string.Empty;
+ if(IsInheritance)
+ template = comboBaseTemplate.SelectedItem.ToString();
+
+ return template;
+ }
}
public string ViewsFolderName
@@ -92,14 +101,22 @@ public string ViewsFolderName
// PRIVATE PROPERTIES
- private bool IsInheritance
+ public bool IsInheritance
{
- get { return (comboBaseTemplate.SelectedItem != null && comboBaseTemplate.SelectedItem.ToString() != TEXT_NONE); }
+ get
+ {
+ return (comboBaseTemplate.SelectedItem != null &&
+ String.CompareOrdinal(comboBaseTemplate.SelectedItem.ToString(), TEXT_NONE) != 0);
+ }
}
- private bool IsViewModel
+ public bool IsViewModel
{
- get { return comboModel.SelectedItem != null && comboModel.SelectedItem.ToString() != TEXT_NONE; }
+ get
+ {
+ return (comboModel.SelectedItem != null &&
+ String.CompareOrdinal(comboModel.SelectedItem.ToString(), TEXT_NONE) != 0);
+ }
}
// METHODS
@@ -163,58 +180,13 @@ private void btnAdd_Click(object sender, EventArgs e)
if (comboBaseTemplate.SelectedItem != null)
wizard.RegisterInserted(comboBaseTemplate.SelectedItem.ToString());
- string itemName = ViewName + ".django";
- string templateFile = Path.GetTempFileName();
- string PreGeneratedTemplateText = string.Empty;
-
- // We need to generate these tags only if we're writing directly to the file. otherwise this will be generated on the fly
- if (IsViewModel && WriteItemDirectly)
- PreGeneratedTemplateText += "{% model Model:" + comboModel.SelectedItem + " %}\r\n";
-
- // We need to generate these tags only if we're writing directly to the file. otherwise this will be generated on the fly
- if (IsInheritance && WriteItemDirectly)
- {
- PreGeneratedTemplateText += "{% extends \"" + comboBaseTemplate.SelectedItem + "\" %}\r\n";
- if (checkedListBlocks.CheckedItems.Count > 0)
- {
- foreach (string name in checkedListBlocks.CheckedItems)
- {
- PreGeneratedTemplateText += "{% block " + name + " %}\r\n";
- PreGeneratedTemplateText += "{% endblock " + name + " %}\r\n";
- }
- }
- }
-
- if (WriteItemDirectly)
- {
- using (StreamWriter sw = new StreamWriter(templateFile))
- {
- sw.WriteLine(PreGeneratedTemplateText);
- sw.Close();
- }
- try
- {
- wizard.AddFromFile(templateFile, itemName);
- this.Close();
- }
- catch (COMException ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- File.Delete(templateFile);
- }
- }
- else
- this.Close();
-
+ Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
- this.Close();
+ Close();
}
private void comboBaseTemplate_SelectedIndexChanged(object sender, EventArgs e)
View
47 NDjangoDesigner/Commands/ViewWizard.cs
@@ -18,15 +18,15 @@
namespace NDjango.Designer.Commands
{
- public class ViewWizard: IVsSelectionEvents
+ public class ViewWizard
{
public static IVsMonitorSelection SelectionService = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));
public static DTE dte = (DTE)Package.GetGlobalService(typeof(DTE));
public static uint contextCookie;
public static uint selectionCookie;
public ViewWizard()
{
- SelectionService.AdviseSelectionEvents(this, out selectionCookie);
+ //SelectionService.AdviseSelectionEvents(this, out selectionCookie);
contextCookie = RegisterContext();
}
@@ -59,12 +59,8 @@ public void Update()
}
}
#region private fields
- // SI: Changed these strings to static as there is a problem with registering onselect event
- // when working with templates. AFAIK there is only one possible thread that works with these variables
- // so this should be safe.
- static string projectDir;
- static string projectName;
- static string viewsFolderName;
+ string projectDir;
+ string viewsFolderName;
INode blockNameNode = null;
Project curProject;
@@ -86,41 +82,6 @@ public string ViewsFolderName
set { viewsFolderName = value; }
}
- int IVsSelectionEvents.OnCmdUIContextChanged(uint dwCmdUICookie, int fActive)
- {
- return VSConstants.S_OK;
- }
- int IVsSelectionEvents.OnElementValueChanged(uint elementid, object varValueOld, object varValueNew)
- {
- return VSConstants.S_OK;
- }
- int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld,IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld,IVsHierarchy pHierNew, uint itemidNew,IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
- {
-
- if (pHierNew != null)
- {
- string itemName;
- //pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out itemName);
- pHierNew.GetCanonicalName(itemidNew, out itemName);
- bool activectx = itemName != null && (itemName.ToString().Contains("Views") ||itemName.ToString().Contains("views"));
- if (activectx)
- {
- object temp;
- hierarchy = pHierNew;
- pHierNew.GetProperty(VSConstants.VSITEMID_ROOT,(int)__VSHPROPID.VSHPROPID_ProjectDir, out temp);
- projectDir = temp.ToString();
- //root = projectFullName.Substring(0, projectFullName.LastIndexOf('\\') + 1);
- pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectName, out temp);
- projectName = temp.ToString();
- viewsFolderName = itemName.ToString();
- }
- int factive = (activectx)? 1 : 0;
- SelectionService.SetCmdUIContext(contextCookie, factive);
-
- }
- return VSConstants.S_OK;
-
- }
public void AddNewItemFromVsTemplate(string templateName, string language, string name)
{
if (name == null)

0 comments on commit e48515d

Please sign in to comment.