Permalink
Browse files

Parse and run tm macros

  • Loading branch information...
1 parent aa96bd7 commit c2a1b7f3a15daaaf3c5a775215ac42c5b168f1b1 Alexander Stigsen committed Jul 8, 2010
Showing with 255 additions and 4 deletions.
  1. +1 −0 src/BundleItemType.h
  2. +6 −2 src/EditorCtrl.cpp
  3. +2 −1 src/EditorCtrl.h
  4. +3 −0 src/IEditorDoAction.h
  5. +79 −0 src/plistHandler.cpp
  6. +1 −0 src/plistHandler.h
  7. +1 −0 src/tmAction.h
  8. +150 −1 src/tm_syntaxhandler.cpp
  9. +12 −0 src/tm_syntaxhandler.h
View
@@ -9,6 +9,7 @@ enum BundleItemType {
BUNDLE_DRAGCMD,
BUNDLE_PREF,
BUNDLE_LANGUAGE,
+ BUNDLE_MACRO,
BUNDLE_MENU,
BUNDLE_SUBDIR,
View
@@ -9792,10 +9792,14 @@ EditorChangeState EditorCtrl::GetChangeState() const {
}
void EditorCtrl::PlayMacro() {
+ PlayMacro(m_macro);
+}
+
+void EditorCtrl::PlayMacro(const eMacro& macro) {
if (m_macro.IsRecording()) m_macro.EndRecording(); // avoid endless loop
- for (size_t i = 0; i < m_macro.GetCount(); ++i) {
- const eMacroCmd& cmd = m_macro.GetCommand(i);
+ for (size_t i = 0; i < macro.GetCount(); ++i) {
+ const eMacroCmd& cmd = macro.GetCommand(i);
PlayCommand(cmd);
}
}
View
@@ -143,7 +143,7 @@ class EditorCtrl : public KeyHookable<wxControl>,
// Drawing & Layout
void EnableRedraw(bool enable) {m_enableDrawing = enable;};
- inline void ReDraw(){DrawLayout();}
+ virtual void ReDraw(){DrawLayout();}
bool Show(bool show);
void SetWordWrap(cxWrapMode wrapMode);
void SetShowGutter(bool showGutter);
@@ -417,6 +417,7 @@ class EditorCtrl : public KeyHookable<wxControl>,
// Macro
void PlayMacro();
+ virtual void PlayMacro(const eMacro& macro);
wxVariant PlayCommand(const eMacroCmd& cmd);
eMacro& GetMacro() {return m_macro;};;
View
@@ -16,10 +16,13 @@
#endif
class tmAction;
+class eMacro;
class IEditorDoAction {
public:
virtual void DoAction(const tmAction& action, const map<wxString, wxString>* envVars, bool isRaw) = 0;
+ virtual void PlayMacro(const eMacro& macro) = 0;
+ virtual void ReDraw() = 0;
};
#endif // __IEDITORDOACTION_H__
View
@@ -97,6 +97,12 @@ const char* PListHandler::DB_BUNDLES_FORMAT =
"loc:I,"
"mod:I,"
"prisref:I,"
+ "localref:I],"
+ "macros["
+ "uuid:S,"
+ "loc:I,"
+ "mod:I,"
+ "prisref:I,"
"localref:I]]";
const char* PListHandler::DB_PLISTS_FORMAT =
@@ -143,6 +149,7 @@ static const c4_ViewProp pFreeStrings("freestrings");
static const c4_StringProp pKey("key");
static const c4_IntProp pLocality("loc");
static const c4_IntProp pLocalRef("localref");
+static const c4_ViewProp pMacros("macros");
static const c4_LongProp pModDate("moddate");
static const c4_IntProp pModified("mod");
static const c4_IntProp pPristineRef("prisref");
@@ -634,6 +641,20 @@ void PListHandler::UpdateBundleSubDirs(const wxFileName& path, int loc, unsigned
UpdatePlists(prefsDir, files, loc, vPrefs);
}
else DeleteAllItems(loc, vPrefs);
+
+ // Update Macros
+ wxFileName macrosDir = path;
+ macrosDir.AppendDir(wxT("Macros"));
+ c4_View vMacros = pMacros(rBundle);
+ if (macrosDir.DirExists()) {
+ wxSortedArrayString files;
+ wxDir::GetAllFiles(macrosDir.GetPath(), &files, wxT("*.plist"), wxDIR_FILES);
+ wxDir::GetAllFiles(macrosDir.GetPath(), &files, wxT("*.tmMacro"), wxDIR_FILES);
+
+ UpdatePlists(macrosDir, files, loc, vMacros);
+ }
+ else DeleteAllItems(loc, vMacros);
+
}
}
@@ -739,6 +760,10 @@ wxString PListHandler::GetBundleItemUri(BundleItemType type, unsigned int bundle
uri += wxT("Syntaxes");
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ uri += wxT("Macros");
+ vItems = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
return wxEmptyString;
@@ -777,6 +802,7 @@ BundleItemType PListHandler::GetBundleTypeFromUri(const wxString& uri) const {
if (itemtype == wxT("DragCommands")) return BUNDLE_DRAGCMD;
if (itemtype == wxT("Preferences")) return BUNDLE_PREF;
if (itemtype == wxT("Syntaxes")) return BUNDLE_LANGUAGE;
+ if (itemtype == wxT("Macros")) return BUNDLE_MACRO;
return BUNDLE_NONE;
}
@@ -821,6 +847,10 @@ bool PListHandler::GetBundleItemFromUri(const wxString& uri, BundleItemType& typ
type = BUNDLE_LANGUAGE;
vItems = pSyntaxes(rBundle);
}
+ else if (itemtype == wxT("Macros")) {
+ type = BUNDLE_MACRO;
+ vItems = pMacros(rBundle);
+ }
else return false;
// Find item with matching name
@@ -900,6 +930,15 @@ bool PListHandler::GetBundleItemFromUuid(const wxString& uuid, BundleItemType& t
itemId = ndx;
return true;
}
+
+ const c4_View vMacros = pMacros(rBundle);
+ ndx = vMacros.Find(rUuid);
+ if (ndx != -1) {
+ type = BUNDLE_MACRO;
+ bundleId = b;
+ itemId = ndx;
+ return true;
+ }
}
return false;
@@ -928,6 +967,9 @@ vector<unsigned int> PListHandler::GetList(BundleItemType type, unsigned int bun
case BUNDLE_LANGUAGE:
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ vItems = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
}
@@ -964,6 +1006,9 @@ PListDict PListHandler::Get(BundleItemType type, unsigned int bundleId, unsigned
case BUNDLE_LANGUAGE:
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ vItems = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
}
@@ -995,6 +1040,9 @@ PListDict PListHandler::GetEditable(BundleItemType type, unsigned int bundleId,
case BUNDLE_LANGUAGE:
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ vItems = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
}
@@ -1028,6 +1076,9 @@ unsigned int PListHandler::New(BundleItemType type, unsigned int bundleId, const
case BUNDLE_LANGUAGE:
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ vItems = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
}
@@ -1064,6 +1115,10 @@ void PListHandler::Delete(BundleItemType type, unsigned int bundleId, unsigned i
path.AppendDir(wxT("Syntaxes"));
vPlists = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ path.AppendDir(wxT("Macros"));
+ vPlists = pMacros(rBundle);
+ break;
default:
wxASSERT(false);
}
@@ -1603,6 +1658,11 @@ bool PListHandler::Save(BundleItemType type, unsigned int bundleId, unsigned int
vPlists = pSyntaxes(rBundle);
ext = wxT(".tmLanguage");
break;
+ case BUNDLE_MACRO:
+ path.AppendDir(wxT("Macros"));
+ vPlists = pMacros(rBundle);
+ ext = wxT(".tmMacro");
+ break;
default:
wxASSERT(false);
}
@@ -1668,6 +1728,10 @@ wxFileName PListHandler::GetBundleItemPath(BundleItemType type, unsigned int bun
path.AppendDir(wxT("Syntaxes"));
vItems = pSyntaxes(rBundle);
break;
+ case BUNDLE_MACRO:
+ path.AppendDir(wxT("Macros"));
+ vItems = pMacros(rBundle);
+ break;
default: wxASSERT(false);
}
@@ -1718,6 +1782,7 @@ bool PListHandler::ExportBundle(const wxFileName& dstPath, unsigned int bundleId
bundleTypes[BUNDLE_DRAGCMD] = wxT("DragCommands");
bundleTypes[BUNDLE_PREF] = wxT("Preferences");
bundleTypes[BUNDLE_LANGUAGE] = wxT("Syntaxes");
+ bundleTypes[BUNDLE_MACRO] = wxT("Macros");
// Copy subdirs
for (map<BundleItemType, wxString>::const_iterator p = bundleTypes.begin(); p != bundleTypes.end(); ++p) {
@@ -2633,6 +2698,20 @@ bool PListDict::GetInteger(const char* key, int& value) const {
return true;
}
+bool PListDict::GetBool(const char* key) const {
+ wxASSERT(m_rPlist);
+ // defaults to false on error
+
+ const int ndx = m_vDict.Find(pKey[key]);
+ if (ndx == -1) return false;
+
+ const c4_RowRef rItem = m_vDict[ndx];
+ if (pType(rItem) != REF_BOOL && pType(rItem) != REF_INTEGER) return false;
+
+ const int value = pRef(rItem);
+ return (value != 0);
+}
+
void PListDict::DeleteItem(const char* key) {
wxASSERT(m_rPlist);
View
@@ -239,6 +239,7 @@ class PListDict : public PListItem {
bool GetDict(const char* key, PListDict& dict) const;
bool GetArray(const char* key, PListArray& array) const;
bool GetInteger(const char* key, int& value) const;
+ bool GetBool(const char* key) const;
void DeleteItem(const char* key);
void SetString(const char* key, const char* text);
View
@@ -22,6 +22,7 @@ class tmAction {
virtual bool IsCommand() const {return false;};
virtual bool IsDrag() const {return false;};
virtual bool IsSyntax() const {return false;};
+ virtual bool IsMacro() const {return false;};
void SwapContent(std::vector<char>& c) {
cmdContent.swap(c);
contentLoaded = true;
Oops, something went wrong.

0 comments on commit c2a1b7f

Please sign in to comment.