public SettingsForm(NemonicForm app) { InitializeComponent(); SettingsForm.App = app; //TabPage를 미리 구상해서 저장해두고, 로딩하는 형식 //MemoTab 구성 this.MemoTab = new TabPage("Memo"); this.MemoCtrl = new MemoCtrl(NemonicApp.MemoPath, this.Hide) { Dock = DockStyle.Fill }; this.MemoTab.Controls.Add(MemoCtrl); this.MemoCtrl.InitializeElements(); //TemplateTab 구성 this.TemplateTab = new TabPage("Template"); this.TemplateCtrl = new TemplateCtrl(NemonicApp.TemplatePath, this.Hide) { Dock = DockStyle.Fill }; this.TemplateTab.Controls.Add(this.TemplateCtrl); this.TemplateCtrl.InitializeElements(); this.SelectTab(Tab.Memo); }
public NemonicContext(NemonicForm form, bool startup = false) { Forms = new Dictionary <string, JsonObject>(); #if (!DEBUG) try #endif { if (File.Exists(ReStartPath)) { string json = File.ReadAllText(ReStartPath); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; List <JsonObject> objects = JsonConvert.DeserializeObject <List <JsonObject> >(json, settings); if (startup && objects.Count < 1) { throw new ApplicationException("No need to start program"); } foreach (JsonObject obj in objects) { Memo memo = obj as Memo; NemonicForm fm = new NemonicForm(path: memo.path); this.OpenNew(fm); fm.Location = new Point(memo.x, memo.y); this.Forms.Add(memo.path, memo); } } } #if (!DEBUG) catch (Exception e) { File.Delete(NemonicContext.ReStartPath); } #endif if (Application.OpenForms.Count == 0) { if (startup) { throw new ApplicationException("No need to start program"); } else { form.FormClosed += OnFormClosed; form.Show(); } } }
/// <summary> /// 새로운 메모장을 연다. /// </summary> /// <param name="templatepath">적용할 템플릿 이미지</param> /// <param name="path">새 메모장에 로드할 JSON 파일 위치</param> public void OpenNew(string templatepath = "null", string path = "null") { Paper paper = this.CurrentPaper; Sticky sticky = this.LayersCtrl.StickyCtrl.CurrentSticky; ColorType color = this.CurrentColor; Image template = null; if (!templatepath.Equals("null")) { template = Image.FromFile(templatepath); } NemonicForm form = new NemonicForm(paper, sticky, color, template, path); NemonicApp.AppContext.OpenNew(form); }
static void Main(string[] args) { Process[] nemonic = Process.GetProcessesByName("nemonic"); if (nemonic.Length > 1) { //TODO: 새 메모장을 열 수 있도록, 기존의 프로세스로 메세지를 보내는 방법이 필요하다. MessageBox.Show("nemonic App already running.", "Notification", MessageBoxButtons.OK); return; } #if (!DEBUG) try #endif { //Arguments 해석하여, 메모에 반영한다. Paper paper = Paper.p80x80; Sticky sticky = Sticky.Top; Image template = null; string path = null; bool startup = false; #if DEBUG //path = @"C:\Users\wlfka\Documents\nemonic\Memo\2017-06-25_10-09-13-오전.nemo"; #endif //TODO: 파라미터를 전달하는 알고리즘을 순서가 상관없도록 하자. ColorType color = ColorType.White; try { if (args.Length >= 1 && args[0] != string.Empty) { Enum.TryParse <Paper>(args[0], out paper); } if (args.Length >= 2 && args[1] != string.Empty) { Enum.TryParse <Sticky>(args[1], out sticky); } if (args.Length >= 3 && args[2] != string.Empty) { Enum.TryParse <ColorType>(args[2], out color); } if (args.Length >= 4 && args[3] != string.Empty) { if (!args[3].Equals("null")) { template = Image.FromFile(args[3]); } } if (args.Length >= 5 && args[4] != string.Empty) { if (!args[4].Equals("null")) { path = args[4]; } } if (args.Length >= 6 && args[5] != string.Empty) { if (args[5].Equals("true")) { startup = true; #if DEBUG //MessageBox.Show("startup = " + startup); #endif } } } catch (Exception e) { #if DEBUG MessageBox.Show("Error! Invalid argument used. \n\n" + e.StackTrace); #endif } //기본적으로 필요한 폴더가 존재하는지 체크하고 생성한다. if (!Directory.Exists(MemoPath)) { Directory.CreateDirectory(MemoPath); } if (!Directory.Exists(TemporaryPath)) { Directory.CreateDirectory(TemporaryPath); } NemonicForm form = new NemonicForm(paper, sticky, color, template, path); Application.EnableVisualStyles(); try { Application.Run(AppContext = new NemonicContext(form, startup)); } catch (ApplicationException e) { #if DEBUG //MessageBox.Show(e.Message); #endif Application.Exit(); } } #if (!DEBUG) catch (Exception e) { //MessageBox.Show("FATAL ERROR!\n" + e.Message +"\n\n" + e.StackTrace); } #endif }
public void OpenNew(NemonicForm form) { form.FormClosed += OnFormClosed; form.Show(); }