From 5d305c971736f0f93d35d28c8bc7ec617962ef15 Mon Sep 17 00:00:00 2001 From: David Freese Date: Mon, 8 Dec 2008 04:02:57 -0600 Subject: [PATCH] Macro tag changes Added macro tag with selected file target Added macro tag with selected file target Deleted update_main_title() from macro save / load Corrected bugs associated with executing /Files/Open macros... a. title bar not changed in macro editor b. altMacros / btnAltMacros not correctly reset --- src/include/macros.h | 1 + src/misc/macroedit.cxx | 27 +++++++++++++++++++++++++++ src/misc/macros.cxx | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/include/macros.h b/src/include/macros.h index 0123fc07..f7e66d10 100644 --- a/src/include/macros.h +++ b/src/include/macros.h @@ -56,6 +56,7 @@ struct MACROTEXT { } private: string expanded; + void loadnewMACROS(string &s, size_t &i); }; extern MACROTEXT macros; diff --git a/src/misc/macroedit.cxx b/src/misc/macroedit.cxx index 2fded97c..ac20f7f3 100644 --- a/src/misc/macroedit.cxx +++ b/src/misc/macroedit.cxx @@ -10,6 +10,7 @@ #include "macroedit.h" #include "globals.h" #include "status.h" +#include "fileselect.h" #include @@ -85,6 +86,10 @@ void loadBrowser(Fl_Widget *widget) { w->add("\tFldigi + version"); w->add("\trepeat every NNN sec"); w->add("\tidle signal for NNN sec"); + + w->add(LINE_SEP); + w->add("\tinsert text file"); + w->add("\tchange macro defs file"); w->add(LINE_SEP); char s[256]; @@ -145,6 +150,23 @@ void cbInsertMacro(Fl_Widget *, void *) text.erase(tab); if (text == LINE_SEP) return; + if (text == "") { + string filters = "Text\t*." "txt"; + const char* p = FSEL::select("Text file to insert", filters.c_str(), + "text." "txt"); + if (p) { + text.insert(6, p); + } else + text = ""; + } else if (text == "") { + string filters = "Macrost\t*." "mdf"; + const char* p = FSEL::select("Change to Macro file", filters.c_str(), + "macros." "mdf"); + if (p) { + text.insert(8, p); + } else + text = ""; + } macrotext->insert(text.c_str()); macrotext->take_focus(); } @@ -181,6 +203,11 @@ Fl_Double_Window* make_macroeditor(void) void editMacro(int n) { if (!MacroEditDialog) MacroEditDialog = make_macroeditor(); + else { + editor_label = ""; + editor_label.append("Macro editor - ").append(progStatus.LastMacroFile); + MacroEditDialog->label(editor_label.c_str()); + } macrotext->value(macros.text[n].c_str()); labeltext->value(macros.name[n].c_str()); iMacro = n; diff --git a/src/misc/macros.cxx b/src/misc/macros.cxx index 2960f2b6..0eb995a8 100644 --- a/src/misc/macros.cxx +++ b/src/misc/macros.cxx @@ -70,6 +70,8 @@ void pGET(string &, size_t &); void pINFO1(string &, size_t &); void pINFO2(string &, size_t &); void pCLRRX(string &, size_t &); +void pFILE(string &, size_t &); +//void pMACROS(string &, size_t &); MTAGS mtags[] = { {"", pCALL}, @@ -112,6 +114,8 @@ MTAGS mtags[] = { {"", pCONT}, {"", pGET}, {"", pCLRRX}, +{"',i); + string fname = s.substr(i+6, endbracket - i - 6); + if (fname.length() > 0) { + FILE *toadd = fopen(fname.c_str(), "r"); + string buffer; + char c = getc(toadd); + while (c && !feof(toadd)) { + if (c != '\r') buffer += c; // damn MSDOS txt files + c = getc(toadd); + } + s.replace(i, endbracket - i + 1, buffer); + fclose(toadd); + } else + s.replace(i, endbracket - i + 1, ""); +} + void pINFO1(string &s, size_t &i) { s.replace( i, 7, info1msg ); @@ -646,6 +668,9 @@ int MACROTEXT::loadMacros(string filename) text[mNumber] = text[mNumber] + mLine; } mFile.close(); + altMacros = 0; + btnAltMacros->label("1"); + btnAltMacros->redraw_label(); return 0; } @@ -675,7 +700,6 @@ void MACROTEXT::openMacroFile() if (p) { loadMacros(p); progStatus.LastMacroFile = fl_filename_name(p); - update_main_title(); } } @@ -687,10 +711,19 @@ void MACROTEXT::saveMacroFile() if (p) { saveMacros(p); progStatus.LastMacroFile = fl_filename_name(p); - update_main_title(); } } +void MACROTEXT::loadnewMACROS(string &s, size_t &i) +{ + size_t endbracket = s.find('>',i); + string fname = s.substr(i+8, endbracket - i - 8); + if (fname.length() > 0) { + loadMacros(fname); + progStatus.LastMacroFile = fl_filename_name(fname.c_str()); + } + s.replace(i, endbracket - i + 1, ""); +} string MACROTEXT::expandMacro(int n) { @@ -702,6 +735,11 @@ string MACROTEXT::expandMacro(int n) MTAGS *pMtags; while ((idx = expanded.find('<', idx)) != string::npos) { + if (expanded.find("", idx) == idx) pCONT(expanded, idx);